mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2026-01-04 10:09:58 +03:00
[WIP] Add NativeDocumentManager to show native symbol informations
This commit is contained in:
@@ -17,7 +17,7 @@ export class GodotTools {
|
||||
|
||||
constructor(p_context: vscode.ExtensionContext) {
|
||||
this.context = p_context;
|
||||
this.client = new GDScriptLanguageClient();
|
||||
this.client = new GDScriptLanguageClient(p_context);
|
||||
this.client.watch_status(this.on_client_status_changed.bind(this));
|
||||
this.connection_status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, RequestMessage, NotificationMessage } from "vscode-languageclient";
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, RequestMessage } from "vscode-languageclient";
|
||||
import { is_debug_mode, get_configuration } from "../utils";
|
||||
import { MessageIO, MessageIOReader, MessageIOWriter } from "./MessageIO";
|
||||
import { ResponseMessage } from "vscode-jsonrpc/lib/messages";
|
||||
import { MessageIO, MessageIOReader, MessageIOWriter, Message } from "./MessageIO";
|
||||
import logger from "../loggger";
|
||||
import { EventEmitter } from "events";
|
||||
type Message = RequestMessage | ResponseMessage | NotificationMessage;
|
||||
import NativeDocumentManager from './NativeDocumentManager';
|
||||
|
||||
function getClientOptions(): LanguageClientOptions {
|
||||
return {
|
||||
@@ -44,11 +43,13 @@ export default class GDScriptLanguageClient extends LanguageClient {
|
||||
|
||||
public io: MessageIO = io;
|
||||
|
||||
private context: vscode.ExtensionContext;
|
||||
private _started : boolean = false;
|
||||
private _status : ClientStatus;
|
||||
private _status_changed_callbacks: ((v : ClientStatus)=>void)[] = [];
|
||||
private _initialize_request: Message = null;
|
||||
private message_handler: MessageHandler = null;
|
||||
private native_doc_manager: NativeDocumentManager = null;
|
||||
|
||||
public get started() : boolean { return this._started; }
|
||||
public get status() : ClientStatus { return this._status; }
|
||||
@@ -67,14 +68,16 @@ export default class GDScriptLanguageClient extends LanguageClient {
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
constructor(context: vscode.ExtensionContext) {
|
||||
super(`GDScriptLanguageClient`, serverOptions, getClientOptions());
|
||||
this.context = context;
|
||||
this.status = ClientStatus.PENDING;
|
||||
this.message_handler = new MessageHandler();
|
||||
this.io.on('disconnected', this.on_disconnected.bind(this));
|
||||
this.io.on('connected', this.on_connected.bind(this));
|
||||
this.io.on('message', this.on_message.bind(this));
|
||||
this.io.on('send_message', this.on_send_message.bind(this));
|
||||
this.native_doc_manager = new NativeDocumentManager(this.io);
|
||||
}
|
||||
|
||||
connect_to_server() {
|
||||
|
||||
@@ -3,7 +3,8 @@ import { EventEmitter } from "events";
|
||||
import * as WebSocket from 'ws';
|
||||
import MessageBuffer from "./MessageBuffer";
|
||||
import { AbstractMessageWriter, MessageWriter } from "vscode-jsonrpc/lib/messageWriter";
|
||||
import { Message } from "vscode-jsonrpc";
|
||||
import { RequestMessage, ResponseMessage, NotificationMessage } from "vscode-jsonrpc/lib/messages";
|
||||
export type Message = RequestMessage | ResponseMessage | NotificationMessage;
|
||||
|
||||
export class MessageIO extends EventEmitter {
|
||||
|
||||
|
||||
65
src/lsp/NativeDocumentManager.ts
Normal file
65
src/lsp/NativeDocumentManager.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { EventEmitter } from "events";
|
||||
import { MessageIO } from "./MessageIO";
|
||||
import { NotificationMessage } from "vscode-jsonrpc";
|
||||
import { DocumentSymbol } from "vscode";
|
||||
const METHOD_ID = 'gdscript/show_native_symbol';
|
||||
|
||||
class GodotNativeSymbol extends DocumentSymbol {
|
||||
documentation: string;
|
||||
native_class: string;
|
||||
};
|
||||
|
||||
export default class NativeDocumentManager extends EventEmitter {
|
||||
|
||||
constructor(io: MessageIO) {
|
||||
super();
|
||||
io.on("message", (message: NotificationMessage)=>{
|
||||
if (message.method == METHOD_ID) {
|
||||
this.show_native_symbol(message.params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private show_native_symbol(symbol: GodotNativeSymbol) {
|
||||
// 创建webview
|
||||
const panel = vscode.window.createWebviewPanel(
|
||||
'doc',
|
||||
symbol.name,
|
||||
vscode.ViewColumn.Nine,
|
||||
{
|
||||
enableScripts: false, // 启用JS,默认禁用
|
||||
retainContextWhenHidden: false, // webview被隐藏时保持状态,避免被重置
|
||||
}
|
||||
);
|
||||
panel.title = symbol.name;
|
||||
panel.webview.html = this.make_html_content(symbol);
|
||||
}
|
||||
|
||||
private make_html_content(symbol: GodotNativeSymbol): string {
|
||||
return `<html><body>${this.make_symbol_document(symbol)}</body></html>`;
|
||||
}
|
||||
|
||||
private make_symbol_document(symbol: GodotNativeSymbol): string {
|
||||
let doc = '';
|
||||
function line(text: string) {
|
||||
doc += text + '\n';
|
||||
};
|
||||
|
||||
switch (symbol.kind) {
|
||||
case vscode.SymbolKind.Class: {
|
||||
line(`<h1>${symbol.detail}</h1>`);
|
||||
line(`<h3>Description</h3>`)
|
||||
line(`<p>${this.parse_markdown(symbol.documentation)}</p>`);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
private parse_markdown(markdown: string): string {
|
||||
return markdown;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user