Skip to content

Commit

Permalink
Release 0.0.10 - Added support for configuring symbol position when n…
Browse files Browse the repository at this point in the history
…avigating
  • Loading branch information
mishkinf committed Jan 30, 2025
1 parent 17b5e88 commit 9bde09a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ This extension provides the following settings that can be configured in your `s
- When `true`: The entire symbol will be selected when navigating
- When `false`: Only the cursor will be moved to the start of the symbol

3. `gotoNextPreviousMember.symbolPosition` (default: `"center"`)
- Controls where the symbol appears in the viewport when navigating
- Possible values:
- `"top"`: Position the symbol at the top of the viewport
- `"center"`: Position the symbol in the center of the viewport
- `"bottom"`: Position the symbol at the bottom of the viewport
- Example setting:

```json
{
"gotoNextPreviousMember.symbolPosition": "top"
}
```

## Language Support

For the outline to work, the language support plugins need to support symbol information.
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "goto-next-previous-member",
"displayName": "Go to Next/Previous Member",
"description": "Visual Studio Code Extenion to navigate through the functions, variables, and classes using quick and easy keycommands similar to functionality provided by IntelliJ IDE's (next/previous function) or Resharper (next/previous member)",
"version": "0.0.9",
"version": "0.0.10",
"publisher": "mishkinf",
"icon": "logo/icon.png",
"engines": {
Expand Down Expand Up @@ -57,6 +57,16 @@
"type": "boolean",
"default": false,
"description": "When true, selects the entire symbol when navigating. When false, only moves the cursor to the start of the symbol."
},
"gotoNextPreviousMember.symbolPosition": {
"type": "string",
"enum": [
"top",
"center",
"bottom"
],
"default": "center",
"description": "Where to position the symbol in the view when navigating (top, center, or bottom of the viewport)"
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export function activate(context: vscode.ExtensionContext) {
let tree: Array<vscode.DocumentSymbol> = [];
let dirtyTree = true;
let selectEntireSymbol: boolean;
let symbolPosition: string;

const reloadConfiguration = () => {
// Get the array of allowed symbols from the config file
let symbolKindsArray: Array<string> | undefined = vscode.workspace.getConfiguration().get<Array<string>>("gotoNextPreviousMember.symbolKinds");
selectEntireSymbol = vscode.workspace.getConfiguration().get<boolean>("gotoNextPreviousMember.selectEntireSymbol", false);
symbolPosition = vscode.workspace.getConfiguration().get<string>("gotoNextPreviousMember.symbolPosition", "center");

// If it's empty or undefined, create an empty Set to allow all symbols
if (!symbolKindsArray || symbolKindsArray.length === 0) {
Expand Down Expand Up @@ -125,6 +127,13 @@ export function activate(context: vscode.ExtensionContext) {
return nextSymbol;
};

const revealSymbol = (symbol: vscode.DocumentSymbol) => {
vscode.commands.executeCommand("revealLine", {
lineNumber: symbol.selectionRange.start.line,
at: symbolPosition
});
};

const previousMemberCommand = vscode.commands.registerTextEditorCommand("gotoNextPreviousMember.previousMember", async (editor: vscode.TextEditor, edit, symbolKinds?: string[]) => {
let symbol;

Expand Down Expand Up @@ -167,10 +176,7 @@ export function activate(context: vscode.ExtensionContext) {
symbol.selectionRange.start.character,
);
}
vscode.commands.executeCommand("revealLine", {
lineNumber: symbol.selectionRange.start.line,
at: "center"
});
revealSymbol(symbol);
}
vscode.window.setStatusBarMessage("Previous Member", 1000);
}
Expand Down Expand Up @@ -218,17 +224,15 @@ export function activate(context: vscode.ExtensionContext) {
symbol.selectionRange.start.character,
);
}
vscode.commands.executeCommand("revealLine", {
lineNumber: symbol.selectionRange.start.line,
at: "center"
});
revealSymbol(symbol);
}
vscode.window.setStatusBarMessage("Next Member", 1000);
}
);

context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('gotoNextPreviousMember.symbolKinds')) {
if (e.affectsConfiguration('gotoNextPreviousMember.symbolKinds') ||
e.affectsConfiguration('gotoNextPreviousMember.symbolPosition')) {
if (vscode.window.activeTextEditor) {
reloadConfiguration();
}
Expand Down

0 comments on commit 9bde09a

Please sign in to comment.