Merge pull request #114186 from voylin/language_server_highlight_support
Add highlight support to Language Server for external editors
This commit is contained in:
commit
8d2c8b5433
4 changed files with 44 additions and 1 deletions
|
|
@ -557,6 +557,7 @@ GDScriptLanguageProtocol::GDScriptLanguageProtocol() {
|
|||
SET_DOCUMENT_METHOD(didSave);
|
||||
|
||||
SET_DOCUMENT_METHOD(documentSymbol);
|
||||
SET_DOCUMENT_METHOD(documentHighlight);
|
||||
SET_DOCUMENT_METHOD(completion);
|
||||
SET_DOCUMENT_METHOD(rename);
|
||||
SET_DOCUMENT_METHOD(prepareRename);
|
||||
|
|
|
|||
|
|
@ -150,6 +150,25 @@ Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) {
|
|||
return arr;
|
||||
}
|
||||
|
||||
Array GDScriptTextDocument::documentHighlight(const Dictionary &p_params) {
|
||||
Array arr;
|
||||
LSP::TextDocumentPositionParams params;
|
||||
params.load(p_params);
|
||||
|
||||
const LSP::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params);
|
||||
if (symbol) {
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(params.textDocument.uri);
|
||||
Vector<LSP::Location> usages = GDScriptLanguageProtocol::get_singleton()->get_workspace()->find_usages_in_file(*symbol, path);
|
||||
|
||||
for (const LSP::Location &usage : usages) {
|
||||
LSP::DocumentHighlight highlight;
|
||||
highlight.range = usage.range;
|
||||
arr.push_back(highlight.to_json());
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
Array GDScriptTextDocument::completion(const Dictionary &p_params) {
|
||||
Array arr;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ public:
|
|||
|
||||
Variant nativeSymbol(const Dictionary &p_params);
|
||||
Array documentSymbol(const Dictionary &p_params);
|
||||
Array documentHighlight(const Dictionary &p_params);
|
||||
Array completion(const Dictionary &p_params);
|
||||
Dictionary resolve(const Dictionary &p_params);
|
||||
Dictionary rename(const Dictionary &p_params);
|
||||
|
|
|
|||
|
|
@ -1761,7 +1761,7 @@ struct ServerCapabilities {
|
|||
/**
|
||||
* The server provides document highlight support.
|
||||
*/
|
||||
bool documentHighlightProvider = false;
|
||||
bool documentHighlightProvider = true;
|
||||
|
||||
/**
|
||||
* The server provides document symbol support.
|
||||
|
|
@ -2118,4 +2118,26 @@ static String marked_documentation(const String &p_bbcode) {
|
|||
}
|
||||
return markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* A document highlight is a range inside a text document which deserves
|
||||
* special attention. Usually a document highlight is visualized by changing
|
||||
* the background color of its range.
|
||||
*/
|
||||
struct DocumentHighlight {
|
||||
/**
|
||||
* The range this highlight applies to.
|
||||
*/
|
||||
Range range;
|
||||
|
||||
_FORCE_INLINE_ Dictionary to_json() const {
|
||||
Dictionary dict;
|
||||
dict["range"] = range.to_json();
|
||||
return dict;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void load(const Dictionary &p_params) {
|
||||
range.load(p_params["range"]);
|
||||
}
|
||||
};
|
||||
} // namespace LSP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue