Skip to content

Commit 6291440

Browse files
committed
extension: always follow cursor in package outline
1 parent 74db76a commit 6291440

4 files changed

Lines changed: 20 additions & 57 deletions

File tree

docs/commands.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ See the currently set GOROOT.
3939

4040
List all the Go tools being used by this extension along with their locations.
4141

42-
### `Package Outline: Enable Follow Cursor`
43-
44-
Keep the Package Outline selection synced with the active editor cursor.
45-
46-
### `Package Outline: Disable Follow Cursor`
47-
48-
Stop syncing the Package Outline selection with the active editor cursor.
49-
5042
### `Package Outline: Sort By Name`
5143

5244
Sort Package Outline symbols alphabetically.

extension/package.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,6 @@
223223
"title": "Go: Locate Configured Go Tools",
224224
"description": "List all the Go tools being used by this extension along with their locations."
225225
},
226-
{
227-
"command": "go.packageOutline.enableFollowCursor",
228-
"title": "Package Outline: Enable Follow Cursor",
229-
"description": "Keep the Package Outline selection synced with the active editor cursor."
230-
},
231-
{
232-
"command": "go.packageOutline.disableFollowCursor",
233-
"title": "Package Outline: Disable Follow Cursor",
234-
"description": "Stop syncing the Package Outline selection with the active editor cursor."
235-
},
236226
{
237227
"command": "go.packageOutline.sortByName",
238228
"title": "Package Outline: Sort By Name",
@@ -3831,16 +3821,6 @@
38313821
"when": "view == go.explorer",
38323822
"group": "navigation"
38333823
},
3834-
{
3835-
"command": "go.packageOutline.enableFollowCursor",
3836-
"when": "view == go.package.outline && !go.packageOutline.followCursor",
3837-
"group": "2_packageOutline"
3838-
},
3839-
{
3840-
"command": "go.packageOutline.disableFollowCursor",
3841-
"when": "view == go.package.outline && go.packageOutline.followCursor",
3842-
"group": "2_packageOutline"
3843-
},
38443824
{
38453825
"command": "go.packageOutline.sortByName",
38463826
"when": "view == go.package.outline && go.packageOutline.sortOrder != 'name'",

extension/src/goPackageOutline.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class GoPackageOutlineProvider implements vscode.TreeDataProvider<Package
3131
private readonly collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
3232
private packageSymbols: PackageSymbol[] = [];
3333
private packageItem = this.createPackageItem();
34-
private followCursor = false;
3534
private sortOrder = PackageOutlineSortOrder.Position;
3635
private lastRevealedSymbol?: PackageSymbol;
3736

@@ -43,12 +42,6 @@ export class GoPackageOutlineProvider implements vscode.TreeDataProvider<Package
4342
});
4443
ctx.subscriptions.push(provider.view);
4544
ctx.subscriptions.push(
46-
vscode.commands.registerCommand('go.packageOutline.enableFollowCursor', () =>
47-
provider.setFollowCursor(true)
48-
),
49-
vscode.commands.registerCommand('go.packageOutline.disableFollowCursor', () =>
50-
provider.setFollowCursor(false)
51-
),
5245
vscode.commands.registerCommand('go.packageOutline.sortByName', () =>
5346
provider.setSortOrder(PackageOutlineSortOrder.Name)
5447
),
@@ -201,16 +194,6 @@ export class GoPackageOutlineProvider implements vscode.TreeDataProvider<Package
201194
return a.range.start.character - b.range.start.character;
202195
}
203196

204-
private setFollowCursor(enabled: boolean) {
205-
if (this.followCursor === enabled) {
206-
return;
207-
}
208-
this.followCursor = enabled;
209-
vscode.commands.executeCommand('setContext', 'go.packageOutline.followCursor', enabled);
210-
this.lastRevealedSymbol = undefined;
211-
void this.revealActiveSymbol(vscode.window.activeTextEditor);
212-
}
213-
214197
private setSortOrder(sortOrder: PackageOutlineSortOrder) {
215198
if (this.sortOrder === sortOrder) {
216199
return;
@@ -223,12 +206,11 @@ export class GoPackageOutlineProvider implements vscode.TreeDataProvider<Package
223206
}
224207

225208
private updateContextKeys() {
226-
vscode.commands.executeCommand('setContext', 'go.packageOutline.followCursor', this.followCursor);
227209
vscode.commands.executeCommand('setContext', 'go.packageOutline.sortOrder', this.sortOrder);
228210
}
229211

230212
private async revealActiveSymbol(editor?: vscode.TextEditor) {
231-
if (!this.followCursor || !this.view || !editor || editor.document !== this.activeDocument) {
213+
if (!this.view || !editor || editor.document !== this.activeDocument) {
232214
return;
233215
}
234216
const symbol = this.findSymbolAtPosition(this.packageSymbols, editor.document.uri, editor.selection.active);

extension/test/integration/goPackageOutline.test.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ suite('GoPackageOutlineProvider', function () {
2929
});
3030

3131
setup(async () => {
32-
await vscode.commands.executeCommand('go.packageOutline.disableFollowCursor');
3332
await vscode.commands.executeCommand('go.packageOutline.sortByPosition');
3433
});
3534

@@ -42,7 +41,7 @@ suite('GoPackageOutlineProvider', function () {
4241
vscode.Uri.file(path.join(fixtureDir, 'symbols_1.go'))
4342
);
4443
await window.showTextDocument(document);
45-
await sleep(500); // wait for gopls response
44+
await waitForOutlineResult(provider, 'package_outline_test');
4645
const res = provider.result;
4746
assert.strictEqual(res?.PackageName, 'package_outline_test');
4847
assert.strictEqual(res?.Files.length, 2);
@@ -56,7 +55,7 @@ suite('GoPackageOutlineProvider', function () {
5655
vscode.Uri.file(path.join(fixtureDir, 'symbols_1.go'))
5756
);
5857
await window.showTextDocument(document);
59-
await sleep(500); // wait for gopls response
58+
await waitForOutlineResult(provider, 'package_outline_test');
6059
await vscode.commands.executeCommand('setContext', 'go.showPackageOutline');
6160
const children = await provider.getChildren();
6261
const receiver = children?.find((symbol) => symbol.label === 'TestReceiver');
@@ -75,7 +74,7 @@ suite('GoPackageOutlineProvider', function () {
7574
vscode.Uri.file(path.join(fixtureDir, 'symbols_1.go'))
7675
);
7776
await window.showTextDocument(document);
78-
await sleep(500); // wait for gopls response
77+
await waitForOutlineResult(provider, 'package_outline_test');
7978
await vscode.commands.executeCommand('setContext', 'go.showPackageOutline');
8079
const children = await provider.getChildren();
8180
const receiver = children?.find((symbol) => symbol.label === 'TestReceiver');
@@ -97,7 +96,7 @@ suite('GoPackageOutlineProvider', function () {
9796
vscode.Uri.file(path.join(fixtureDir, 'symbols_1.go'))
9897
);
9998
await window.showTextDocument(document);
100-
await sleep(500); // wait for gopls response
99+
await waitForOutlineResult(provider, 'package_outline_test');
101100
await vscode.commands.executeCommand('go.packageOutline.sortByName');
102101
const children = await provider.getChildren();
103102
assert.deepStrictEqual(
@@ -118,21 +117,20 @@ suite('GoPackageOutlineProvider', function () {
118117
vscode.Uri.file(path.join(fixtureDir, 'symbols_1.go'))
119118
);
120119
await window.showTextDocument(document);
121-
await sleep(500); // wait for gopls response
120+
await waitForOutlineResult(provider, 'package_outline_test');
122121
const children = await provider.getChildren();
123122
assert.deepStrictEqual(
124123
(children ?? []).slice(1).map((symbol) => symbol.label),
125124
['print', 'main', 'TestReceiver']
126125
);
127126
});
128127

129-
test('follow cursor selects the active symbol', async () => {
128+
test('cursor changes reveal the active symbol', async () => {
130129
const document1 = await vscode.workspace.openTextDocument(
131130
vscode.Uri.file(path.join(fixtureDir, 'symbols_1.go'))
132131
);
133132
await window.showTextDocument(document1);
134-
await sleep(500); // wait for gopls response
135-
await vscode.commands.executeCommand('go.packageOutline.enableFollowCursor');
133+
await waitForOutlineResult(provider, 'package_outline_test');
136134
await moveCursor(document1, 19);
137135
await sleep(500); // wait for tree view reveal
138136
assert.strictEqual(
@@ -144,7 +142,7 @@ suite('GoPackageOutlineProvider', function () {
144142
vscode.Uri.file(path.join(fixtureDir, 'symbols_2.go'))
145143
);
146144
await window.showTextDocument(document2);
147-
await sleep(500); // wait for gopls response
145+
await waitForOutlineResult(provider, 'package_outline_test');
148146
await moveCursor(document2, 2);
149147
await sleep(500); // wait for tree view reveal
150148
assert.strictEqual(
@@ -167,6 +165,17 @@ function sleep(ms: number) {
167165
return new Promise((resolve) => setTimeout(resolve, ms));
168166
}
169167

168+
async function waitForOutlineResult(provider: GoPackageOutlineProvider, packageName: string) {
169+
const deadline = Date.now() + 5000;
170+
while (Date.now() < deadline) {
171+
if (provider.result?.PackageName === packageName) {
172+
return;
173+
}
174+
await sleep(100);
175+
}
176+
assert.fail(`timed out waiting for outline result for ${packageName}`);
177+
}
178+
170179
async function moveCursor(document: vscode.TextDocument, line: number, character = 0) {
171180
const editor = await window.showTextDocument(document);
172181
const position = new vscode.Position(line, character);

0 commit comments

Comments
 (0)