Skip to content

Commit

Permalink
Add "Open Type Documentation" context menu option (#405)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo Locurcio <[email protected]>
  • Loading branch information
DaelonSuzuka and Calinou authored Aug 22, 2022
1 parent 441873e commit e7674c1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
"command": "godot-tool.list_native_classes",
"title": "Godot Tools: List native classes of godot"
},
{
"command": "godot-tool.open_type_documentation",
"title": "Godot Tools: Open Type Documentation"
},
{
"command": "godot-tool.debugger.inspect_node",
"title": "Inspect Remote Node",
Expand Down Expand Up @@ -392,6 +396,13 @@
"command": "godot-tool.copy_resource_path_context",
"group": "1_godot"
}
],
"editor/context": [
{
"command": "godot-tool.open_type_documentation",
"when": "godotTools.connectedToEditor",
"group": "navigation@9"
}
]
}
},
Expand Down
20 changes: 18 additions & 2 deletions src/godot-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export class GodotTools {
vscode.commands.registerCommand("godot-tool.set_scene_file", this.set_scene_file.bind(this));
vscode.commands.registerCommand("godot-tool.copy_resource_path_context", this.copy_resource_path.bind(this));
vscode.commands.registerCommand("godot-tool.copy_resource_path", this.copy_resource_path.bind(this));
vscode.commands.registerCommand("godot-tool.open_type_documentation", this.open_type_documentation.bind(this));

vscode.commands.executeCommand('setContext', 'godotTools.connectedToEditor', false);

this.connection_status.text = "$(sync) Initializing";
this.connection_status.command = "godot-tool.check_status";
Expand Down Expand Up @@ -94,7 +97,7 @@ export class GodotTools {
if (!this.project_dir) {
return;
}
if (!uri) {
uri = vscode.window.activeTextEditor.document.uri;
}
Expand All @@ -104,7 +107,18 @@ export class GodotTools {
relative_path = 'res://' + relative_path;

vscode.env.clipboard.writeText(relative_path);
}
}

private open_type_documentation(uri: vscode.Uri) {
// get word under cursor
const activeEditor = vscode.window.activeTextEditor;
const document = activeEditor.document;
const curPos = activeEditor.selection.active;
const wordRange = document.getWordRangeAtPosition(curPos);
const symbolName = document.getText(wordRange);

this.client.open_documentation(symbolName);
}

private set_scene_file(uri: vscode.Uri) {
let right_clicked_scene_path = uri.fsPath;
Expand Down Expand Up @@ -231,6 +245,7 @@ export class GodotTools {
break;
case ClientStatus.CONNECTED:
this.retry = false;
vscode.commands.executeCommand('setContext', 'godotTools.connectedToEditor', true);
this.connection_status.text = `$(check) Connected`;
this.connection_status.tooltip = `Connected to the GDScript language server.`;
if (!this.client.started) {
Expand All @@ -242,6 +257,7 @@ export class GodotTools {
this.connection_status.text = `$(sync) Connecting ` + this.reconnection_attempts;
this.connection_status.tooltip = `Connecting to the GDScript language server...`;
} else {
vscode.commands.executeCommand('setContext', 'godotTools.connectedToEditor', false);
this.connection_status.text = `$(x) Disconnected`;
this.connection_status.tooltip = `Disconnected from the GDScript language server.`;
}
Expand Down
4 changes: 4 additions & 0 deletions src/lsp/GDScriptLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class GDScriptLanguageClient extends LanguageClient {
}
}

public open_documentation(symbolName: string) {
this.native_doc_manager.request_documentation(symbolName);
}

constructor(context: vscode.ExtensionContext) {
super(
`GDScriptLanguageClient`,
Expand Down
9 changes: 9 additions & 0 deletions src/lsp/NativeDocumentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export default class NativeDocumentManager extends EventEmitter {
);
}

public request_documentation(symbolName: string) {
if (symbolName in this.native_classes) {
this.inspect_native_symbol({
native_class: symbolName,
symbol_name: symbolName,
});
}
}

private async list_native_classes() {
let classname = await vscode.window.showQuickPick(
Object.keys(this.native_classes).sort(),
Expand Down

0 comments on commit e7674c1

Please sign in to comment.