Skip to content

Commit

Permalink
Improve docs viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
DaelonSuzuka committed Nov 29, 2023
1 parent 9a71e78 commit 5cd821f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"contributes": {
"customEditors": [
{
"viewType": "godotDocs",
"displayName": "godotDocs",
"viewType": "gddoc",
"displayName": "Godot Documentation",
"selector": [
{
"filenamePattern": "*.godotDocs"
"filenamePattern": "*.gddoc"
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions src/lsp/DefinitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export class DefinitionProvider implements vscode.DefinitionProvider {
const key = `${document.uri},${position.line},${position.character - 1}`;
target = this.data.get(key);
}
log.debug("provideDefinition", key, target);

if (!target) {
return null;
}

const parts = target.split(".");
const uri = vscode.Uri.from({
scheme: "godotDocs",
path: target.split(".").join("/") + ".godotDocs",
scheme: "gddoc",
path: parts[0] + ".gddoc",
fragment: parts[1],
});

log.debug("provideDefinition", uri);
return new vscode.Location(uri, new vscode.Position(0, 0));
}
}
17 changes: 11 additions & 6 deletions src/lsp/NativeDocumentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class NativeDocumentManager extends EventEmitter implements vscode.Custom
supportsMultipleEditorsPerDocument: true,
};
context.subscriptions.push(
vscode.window.registerCustomEditorProvider("godotDocs", this, options),
vscode.window.registerCustomEditorProvider("gddoc", this, options),
);
}

Expand All @@ -57,7 +57,10 @@ export class NativeDocumentManager extends EventEmitter implements vscode.Custom
}

resolveCustomEditor(document: vscode.CustomDocument, webviewPanel: vscode.WebviewPanel, token: vscode.CancellationToken): void {
const symbol = document.uri.path.split(".")[0].replace("/", ".");
let symbol = document.uri.path.split(".")[0];
if (document.uri.fragment) {
symbol += `.${document.uri.fragment}`;
}

this.webViews.set(symbol, webviewPanel);
webviewPanel.title = symbol;
Expand Down Expand Up @@ -155,12 +158,14 @@ export class NativeDocumentManager extends EventEmitter implements vscode.Custom
if (this.webViews.has(key)) {
panel = this.webViews.get(key);
this.webViews.delete(key);
panel.webview.viewColumn = this.get_new_native_symbol_column();
} else {
panel = vscode.window.createWebviewPanel(
"doc",
symbol.name,
this.get_new_native_symbol_column(),
"gddoc",
symbol.name + ".gddoc",
{
viewColumn: this.get_new_native_symbol_column(),
preserveFocus: true,
},
{
enableScripts: true,
retainContextWhenHidden: true,
Expand Down

0 comments on commit 5cd821f

Please sign in to comment.