|
9 | 9 |
|
10 | 10 | void WorkspaceFolder::openTextDocument(const lsp::DocumentUri& uri, const lsp::DidOpenTextDocumentParams& params) |
11 | 11 | { |
12 | | - auto moduleName = fileResolver.getModuleName(uri); |
| 12 | + auto normalisedUri = fileResolver.normalisedUriString(uri); |
| 13 | + |
13 | 14 | fileResolver.managedFiles.emplace( |
14 | | - std::make_pair(moduleName, TextDocument(uri, params.textDocument.languageId, params.textDocument.version, params.textDocument.text))); |
| 15 | + std::make_pair(normalisedUri, TextDocument(uri, params.textDocument.languageId, params.textDocument.version, params.textDocument.text))); |
| 16 | + |
15 | 17 | // Mark the file as dirty as we don't know what changes were made to it |
| 18 | + auto moduleName = fileResolver.getModuleName(uri); |
16 | 19 | frontend.markDirty(moduleName); |
17 | 20 | } |
18 | 21 |
|
19 | 22 | void WorkspaceFolder::updateTextDocument( |
20 | 23 | const lsp::DocumentUri& uri, const lsp::DidChangeTextDocumentParams& params, std::vector<Luau::ModuleName>* markedDirty) |
21 | 24 | { |
22 | | - auto moduleName = fileResolver.getModuleName(uri); |
| 25 | + auto normalisedUri = fileResolver.normalisedUriString(uri); |
23 | 26 |
|
24 | | - if (!contains(fileResolver.managedFiles, moduleName)) |
| 27 | + if (!contains(fileResolver.managedFiles, normalisedUri)) |
25 | 28 | { |
26 | | - // Check if we have the original file URI stored (https://github.com/JohnnyMorganz/luau-lsp/issues/26) |
27 | | - // TODO: can be potentially removed when server generates sourcemap |
28 | | - auto fsPath = uri.fsPath().generic_string(); |
29 | | - if (fsPath != moduleName && contains(fileResolver.managedFiles, fsPath)) |
30 | | - { |
31 | | - // Change the managed file key to use the new modulename |
32 | | - auto nh = fileResolver.managedFiles.extract(fsPath); |
33 | | - nh.key() = moduleName; |
34 | | - fileResolver.managedFiles.insert(std::move(nh)); |
35 | | - } |
36 | | - else |
37 | | - { |
38 | | - client->sendLogMessage(lsp::MessageType::Error, "Text Document not loaded locally: " + uri.toString()); |
39 | | - return; |
40 | | - } |
| 29 | + client->sendLogMessage(lsp::MessageType::Error, "Text Document not loaded locally: " + uri.toString()); |
| 30 | + return; |
41 | 31 | } |
42 | | - auto& textDocument = fileResolver.managedFiles.at(moduleName); |
| 32 | + auto& textDocument = fileResolver.managedFiles.at(normalisedUri); |
43 | 33 | textDocument.update(params.contentChanges, params.textDocument.version); |
44 | 34 |
|
45 | 35 | // Mark the module dirty for the typechecker |
| 36 | + auto moduleName = fileResolver.getModuleName(uri); |
46 | 37 | frontend.markDirty(moduleName, markedDirty); |
47 | 38 | } |
48 | 39 |
|
49 | 40 | void WorkspaceFolder::closeTextDocument(const lsp::DocumentUri& uri) |
50 | 41 | { |
51 | | - auto config = client->getConfiguration(rootUri); |
52 | | - auto moduleName = fileResolver.getModuleName(uri); |
53 | | - fileResolver.managedFiles.erase(moduleName); |
54 | | - |
55 | | - // Clear out base uri fsPath as well, in case we managed it like that |
56 | | - // TODO: can be potentially removed when server generates sourcemap |
57 | | - fileResolver.managedFiles.erase(uri.fsPath().generic_string()); |
| 42 | + fileResolver.managedFiles.erase(fileResolver.normalisedUriString(uri)); |
58 | 43 |
|
59 | 44 | // Mark the module as dirty as we no longer track its changes |
| 45 | + auto config = client->getConfiguration(rootUri); |
| 46 | + auto moduleName = fileResolver.getModuleName(uri); |
60 | 47 | frontend.markDirty(moduleName); |
61 | 48 |
|
62 | 49 | // Refresh workspace diagnostics to clear diagnostics on ignored files |
@@ -137,29 +124,6 @@ bool WorkspaceFolder::updateSourceMap() |
137 | 124 | frontend.typeChecker, instanceTypes, fileResolver, /* TODO - expressiveTypes: */ config.diagnostics.strictDatamodelTypes); |
138 | 125 | types::registerInstanceTypes(frontend.typeCheckerForAutocomplete, instanceTypes, fileResolver, /* TODO - expressiveTypes: */ true); |
139 | 126 |
|
140 | | - // Update managed file paths as they may be converted to virtual |
141 | | - // Check if we have the original file URIs stored (https://github.com/JohnnyMorganz/luau-lsp/issues/26) |
142 | | - std::vector<std::pair<Luau::ModuleName, TextDocument>> movedFiles; |
143 | | - for (auto it = fileResolver.managedFiles.begin(); it != fileResolver.managedFiles.end();) |
144 | | - { |
145 | | - if (!fileResolver.isVirtualPath(it->first)) |
146 | | - { |
147 | | - if (auto virtualPath = fileResolver.resolveToVirtualPath(it->first); virtualPath && virtualPath != it->first) |
148 | | - { |
149 | | - // Store the new ModuleName pairing into a vector and remove the old key |
150 | | - movedFiles.emplace_back(std::make_pair(*virtualPath, it->second)); |
151 | | - it = fileResolver.managedFiles.erase(it); |
152 | | - continue; // Ensure we continue so we don't increment iterator and skip next element |
153 | | - } |
154 | | - } |
155 | | - |
156 | | - it++; |
157 | | - } |
158 | | - |
159 | | - // Add any new pairings back into the map |
160 | | - for (auto& pair : movedFiles) |
161 | | - fileResolver.managedFiles.emplace(pair); |
162 | | - |
163 | 127 | return true; |
164 | 128 | } |
165 | 129 | else |
|
0 commit comments