From 107167ae36850587abf9bde8d14332f65c12f655 Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Thu, 11 Aug 2022 16:07:57 -0400 Subject: [PATCH 1/5] Add `Open Symbol Documentation` context menu option --- package.json | 10 ++++++++++ src/godot-tools.ts | 12 ++++++++++++ src/lsp/GDScriptLanguageClient.ts | 4 ++++ src/lsp/NativeDocumentManager.ts | 9 +++++++++ 4 files changed, 35 insertions(+) diff --git a/package.json b/package.json index 99ee60cfd..7dfc92324 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,10 @@ "command": "godot-tool.list_native_classes", "title": "Godot Tools: List native classes of godot" }, + { + "command": "godot-tool.open_symbol_documentation", + "title": "Open Symbol Documentation" + }, { "command": "godot-tool.debugger.inspect_node", "title": "Inspect Remote Node", @@ -385,6 +389,12 @@ "command": "godot-tool.copy_resource_path_context", "group": "1_godot" } + ], + "editor/context": [ + { + "command": "godot-tool.open_symbol_documentation", + "group": "navigation@9" + } ] } }, diff --git a/src/godot-tools.ts b/src/godot-tools.ts index 0aef7c0c6..9f83bbdd6 100644 --- a/src/godot-tools.ts +++ b/src/godot-tools.ts @@ -44,6 +44,7 @@ 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_symbol_documentation", this.open_symbol_documentation.bind(this)); this.connection_status.text = "$(sync) Initializing"; this.connection_status.command = "godot-tool.check_status"; @@ -101,6 +102,17 @@ export class GodotTools { vscode.env.clipboard.writeText(relative_path); } + private open_symbol_documentation(uri: vscode.Uri) { + // get word under cursor + let activeEditor = vscode.window.activeTextEditor; + let document = activeEditor.document; + let curPos = activeEditor.selection.active; + let wordRange = document.getWordRangeAtPosition(curPos); + let symbolName = document.getText(wordRange); + + this.client.open_documentation(symbolName); + } + private set_scene_file(uri: vscode.Uri) { let right_clicked_scene_path = uri.fsPath; let scene_config = get_configuration("scene_file_config"); diff --git a/src/lsp/GDScriptLanguageClient.ts b/src/lsp/GDScriptLanguageClient.ts index bd6388119..406cf34d3 100644 --- a/src/lsp/GDScriptLanguageClient.ts +++ b/src/lsp/GDScriptLanguageClient.ts @@ -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`, diff --git a/src/lsp/NativeDocumentManager.ts b/src/lsp/NativeDocumentManager.ts index 779061486..b10949c5c 100644 --- a/src/lsp/NativeDocumentManager.ts +++ b/src/lsp/NativeDocumentManager.ts @@ -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(), From b3ac774a60f14a3364bc89af106a05a12611a60b Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Fri, 12 Aug 2022 21:20:24 -0400 Subject: [PATCH 2/5] Rename menu option to indicate limited functionality --- package.json | 6 +++--- src/godot-tools.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7dfc92324..16ffbb786 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,8 @@ "title": "Godot Tools: List native classes of godot" }, { - "command": "godot-tool.open_symbol_documentation", - "title": "Open Symbol Documentation" + "command": "godot-tool.open_type_documentation", + "title": "Godot Tools: Open Type Documentation" }, { "command": "godot-tool.debugger.inspect_node", @@ -392,7 +392,7 @@ ], "editor/context": [ { - "command": "godot-tool.open_symbol_documentation", + "command": "godot-tool.open_type_documentation", "group": "navigation@9" } ] diff --git a/src/godot-tools.ts b/src/godot-tools.ts index 9f83bbdd6..0485835e4 100644 --- a/src/godot-tools.ts +++ b/src/godot-tools.ts @@ -44,7 +44,7 @@ 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_symbol_documentation", this.open_symbol_documentation.bind(this)); + vscode.commands.registerCommand("godot-tool.open_type_documentation", this.open_type_documentation.bind(this)); this.connection_status.text = "$(sync) Initializing"; this.connection_status.command = "godot-tool.check_status"; @@ -102,7 +102,7 @@ export class GodotTools { vscode.env.clipboard.writeText(relative_path); } - private open_symbol_documentation(uri: vscode.Uri) { + private open_type_documentation(uri: vscode.Uri) { // get word under cursor let activeEditor = vscode.window.activeTextEditor; let document = activeEditor.document; From 52c9e8eb738807c5f3da519731546f600e1ed4bb Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Fri, 12 Aug 2022 21:36:45 -0400 Subject: [PATCH 3/5] Add `connectedToEditor` context for when clauses --- package.json | 1 + src/godot-tools.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index 16ffbb786..717139938 100644 --- a/package.json +++ b/package.json @@ -393,6 +393,7 @@ "editor/context": [ { "command": "godot-tool.open_type_documentation", + "when": "godotTools.connectedToEditor", "group": "navigation@9" } ] diff --git a/src/godot-tools.ts b/src/godot-tools.ts index 0485835e4..d321dec14 100644 --- a/src/godot-tools.ts +++ b/src/godot-tools.ts @@ -46,6 +46,8 @@ export class GodotTools { 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"; this.connection_status.show(); @@ -238,6 +240,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) { @@ -249,6 +252,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.`; } From 3d403a2db6d718d7da94a797145cfc2b19bd87dc Mon Sep 17 00:00:00 2001 From: Daelon Suzuka Date: Sun, 21 Aug 2022 16:41:09 -0700 Subject: [PATCH 4/5] Replace let with const Co-authored-by: Hugo Locurcio --- src/godot-tools.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/godot-tools.ts b/src/godot-tools.ts index d321dec14..312a54661 100644 --- a/src/godot-tools.ts +++ b/src/godot-tools.ts @@ -106,11 +106,11 @@ export class GodotTools { private open_type_documentation(uri: vscode.Uri) { // get word under cursor - let activeEditor = vscode.window.activeTextEditor; - let document = activeEditor.document; - let curPos = activeEditor.selection.active; - let wordRange = document.getWordRangeAtPosition(curPos); - let symbolName = document.getText(wordRange); + 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); } From fb6f5e128c6c4e5dfb22dac099e399a0fefa72b0 Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Sun, 21 Aug 2022 19:43:40 -0400 Subject: [PATCH 5/5] Convert spaces to tabs --- src/godot-tools.ts | 28 ++++++++++++++-------------- src/lsp/GDScriptLanguageClient.ts | 6 +++--- src/lsp/NativeDocumentManager.ts | 16 ++++++++-------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/godot-tools.ts b/src/godot-tools.ts index 312a54661..64a9d8633 100644 --- a/src/godot-tools.ts +++ b/src/godot-tools.ts @@ -46,7 +46,7 @@ export class GodotTools { 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); + vscode.commands.executeCommand('setContext', 'godotTools.connectedToEditor', false); this.connection_status.text = "$(sync) Initializing"; this.connection_status.command = "godot-tool.check_status"; @@ -92,7 +92,7 @@ export class GodotTools { if (!this.project_dir) { return; } - + if (!uri) { uri = vscode.window.activeTextEditor.document.uri; } @@ -102,18 +102,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); + 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); - } + this.client.open_documentation(symbolName); + } private set_scene_file(uri: vscode.Uri) { let right_clicked_scene_path = uri.fsPath; @@ -240,7 +240,7 @@ export class GodotTools { break; case ClientStatus.CONNECTED: this.retry = false; - vscode.commands.executeCommand('setContext', 'godotTools.connectedToEditor', true); + 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) { @@ -252,7 +252,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); + vscode.commands.executeCommand('setContext', 'godotTools.connectedToEditor', false); this.connection_status.text = `$(x) Disconnected`; this.connection_status.tooltip = `Disconnected from the GDScript language server.`; } diff --git a/src/lsp/GDScriptLanguageClient.ts b/src/lsp/GDScriptLanguageClient.ts index 406cf34d3..a5ce6b3c2 100644 --- a/src/lsp/GDScriptLanguageClient.ts +++ b/src/lsp/GDScriptLanguageClient.ts @@ -42,9 +42,9 @@ export default class GDScriptLanguageClient extends LanguageClient { } } - public open_documentation(symbolName: string) { - this.native_doc_manager.request_documentation(symbolName); - } + public open_documentation(symbolName: string) { + this.native_doc_manager.request_documentation(symbolName); + } constructor(context: vscode.ExtensionContext) { super( diff --git a/src/lsp/NativeDocumentManager.ts b/src/lsp/NativeDocumentManager.ts index b10949c5c..f10fb97ff 100644 --- a/src/lsp/NativeDocumentManager.ts +++ b/src/lsp/NativeDocumentManager.ts @@ -59,14 +59,14 @@ 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, - }); - } - } + 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(