Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Open Type Documentation" context menu option #405

Merged
merged 5 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -385,6 +389,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 @@ -44,6 +44,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 @@ -89,7 +92,7 @@ export class GodotTools {
if (!this.project_dir) {
return;
}
if (!uri) {
uri = vscode.window.activeTextEditor.document.uri;
}
Expand All @@ -99,7 +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);

this.client.open_documentation(symbolName);
}

private set_scene_file(uri: vscode.Uri) {
let right_clicked_scene_path = uri.fsPath;
Expand Down Expand Up @@ -226,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) {
Expand All @@ -237,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.`;
}
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