1 module dls.protocol.messages.workspace; 2 3 import logger = std.experimental.logger; 4 import dls.protocol.interfaces; 5 import dls.tools.tools : Tools; 6 7 void workspaceFolders(string id, Nullable!(WorkspaceFolder[]) folders) 8 { 9 import dls.util.uri : Uri; 10 import std.path : dirName; 11 12 if (!folders.isNull) 13 { 14 foreach (workspaceFolder; folders) 15 { 16 auto uri = new Uri(workspaceFolder.uri); 17 Tools.codeCompleter.importPath(uri); 18 Tools.codeCompleter.importSelections(uri); 19 } 20 } 21 } 22 23 void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) 24 { 25 workspaceFolders(null, params.event.added.nullable); 26 } 27 28 void configuration(string id, JSONValue[] config) 29 { 30 } 31 32 void didChangeConfiguration(DidChangeConfigurationParams params) 33 { 34 import dls.tools.configuration : Configuration; 35 import dls.util.json : convertFromJSON; 36 37 logger.log("Configuration changed"); 38 39 if ("d" in params.settings && "dls" in params.settings["d"]) 40 { 41 logger.log("Applying new configuration"); 42 Tools.setConfiguration(convertFromJSON!Configuration(params.settings["d"]["dls"])); 43 } 44 } 45 46 void didChangeWatchedFiles(DidChangeWatchedFilesParams params) 47 { 48 import dls.server : Server; 49 import dls.protocol.messages.window : Util; 50 import dls.util.uri : Uri; 51 import std.algorithm : canFind; 52 import std.path : baseName, dirName; 53 54 foreach (event; params.changes) 55 { 56 auto uri = new Uri(event.uri); 57 auto fileName = baseName(uri.path); 58 59 logger.logf("File changed: %s", uri.path); 60 61 if (["dub.json", "dub.sdl"].canFind(fileName)) 62 { 63 auto p = new ShowMessageRequestParams(); 64 p.type = MessageType.info; 65 p.message = fileName ~ " was updated. Upgrade dependencies ?"; 66 p.actions = [new MessageActionItem(), new MessageActionItem()]; 67 p.actions[0].title = "Yes"; 68 p.actions[1].title = "No"; 69 auto id = Server.send("window/showMessageRequest", p); 70 Util.addMessageRequestType(id, Util.ShowMessageRequestType.upgradeSelections, uri); 71 } 72 else if (fileName == "dub.selections.json") 73 { 74 Tools.codeCompleter.importSelections(uri); 75 } 76 } 77 } 78 79 auto symbol(WorkspaceSymbolParams params) 80 { 81 SymbolInformation[] result; 82 return result; 83 } 84 85 auto executeCommand(ExecuteCommandParams params) 86 { 87 auto result = JSONValue(null); 88 return result; 89 } 90 91 void applyEdit(string id, ApplyWorkspaceEditResponse response) 92 { 93 }