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

Implement LSP didDeleteFiles to clear diagnostics #47553

Merged
merged 1 commit into from
Apr 1, 2021
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 modules/gdscript/language_server/gdscript_workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "scene/resources/packed_scene.h"

void GDScriptWorkspace::_bind_methods() {
ClassDB::bind_method(D_METHOD("didDeleteFiles"), &GDScriptWorkspace::did_delete_files);
ClassDB::bind_method(D_METHOD("symbol"), &GDScriptWorkspace::symbol);
ClassDB::bind_method(D_METHOD("parse_script", "path", "content"), &GDScriptWorkspace::parse_script);
ClassDB::bind_method(D_METHOD("parse_local_script", "path"), &GDScriptWorkspace::parse_local_script);
Expand All @@ -50,6 +51,16 @@ void GDScriptWorkspace::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_script_api", "path"), &GDScriptWorkspace::generate_script_api);
}

void GDScriptWorkspace::did_delete_files(const Dictionary &p_params) {
Array files = p_params["files"];
for (int i = 0; i < files.size(); ++i) {
Dictionary file = files[i];
String uri = file["uri"];
String path = get_file_path(uri);
parse_script(path, "");
}
}

void GDScriptWorkspace::remove_cache_parser(const String &p_path) {
Map<String, ExtendGDScriptParser *>::Element *parser = parse_results.find(p_path);
Map<String, ExtendGDScriptParser *>::Element *script = scripts.find(p_path);
Expand Down
2 changes: 2 additions & 0 deletions modules/gdscript/language_server/gdscript_workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class GDScriptWorkspace : public Reference {
Dictionary generate_script_api(const String &p_path);
Error resolve_signature(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::SignatureHelp &r_signature);

void did_delete_files(const Dictionary &p_params);

GDScriptWorkspace();
~GDScriptWorkspace();
};
Expand Down
114 changes: 114 additions & 0 deletions modules/gdscript/language_server/lsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,114 @@ struct SignatureHelp {
}
};

/**
* A pattern to describe in which file operation requests or notifications
* the server is interested in.
*/
struct FileOperationPattern {
/**
* The glob pattern to match.
*/
String glob = "**/*.gd";

/**
* Whether to match `file`s or `folder`s with this pattern.
*
* Matches both if undefined.
*/
String matches = "file";

Dictionary to_json() const {
Dictionary dict;

dict["glob"] = glob;
dict["matches"] = matches;

return dict;
}
};

/**
* A filter to describe in which file operation requests or notifications
* the server is interested in.
*/
struct FileOperationFilter {
/**
* The actual file operation pattern.
*/
FileOperationPattern pattern;

Dictionary to_json() const {
Dictionary dict;

dict["pattern"] = pattern.to_json();

return dict;
}
};

/**
* The options to register for file operations.
*/
struct FileOperationRegistrationOptions {
/**
* The actual filters.
*/
Vector<FileOperationFilter> filters;

FileOperationRegistrationOptions() {
filters.push_back(FileOperationFilter());
}

Dictionary to_json() const {
Dictionary dict;

Array filts;
for (int i = 0; i < filters.size(); i++) {
filts.push_back(filters[i].to_json());
}
dict["filters"] = filts;

return dict;
}
};

/**
* The server is interested in file notifications/requests.
*/
struct FileOperations {
/**
* The server is interested in receiving didDeleteFiles file notifications.
*/
FileOperationRegistrationOptions didDelete;

Dictionary to_json() const {
Dictionary dict;

dict["didDelete"] = didDelete.to_json();

return dict;
}
};

/**
* Workspace specific server capabilities
*/
struct Workspace {
/**
* The server is interested in file notifications/requests.
*/
FileOperations fileOperations;

Dictionary to_json() const {
Dictionary dict;

dict["fileOperations"] = fileOperations.to_json();

return dict;
}
};

struct ServerCapabilities {
/**
* Defines how text documents are synced. Is either a detailed structure defining each notification or
Expand Down Expand Up @@ -1575,6 +1683,11 @@ struct ServerCapabilities {
*/
bool workspaceSymbolProvider = true;

/**
* The server supports workspace folder.
*/
Workspace workspace;

/**
* The server provides code actions. The `CodeActionOptions` return type is only
* valid if the client signals code action literal support via the property
Expand Down Expand Up @@ -1662,6 +1775,7 @@ struct ServerCapabilities {
dict["documentHighlightProvider"] = documentHighlightProvider;
dict["documentSymbolProvider"] = documentSymbolProvider;
dict["workspaceSymbolProvider"] = workspaceSymbolProvider;
dict["workspace"] = workspace.to_json();
dict["codeActionProvider"] = codeActionProvider;
dict["documentFormattingProvider"] = documentFormattingProvider;
dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider;
Expand Down