@@ -28,7 +28,6 @@ getRemappedFiles(const DocumentStore &Docs) {
28
28
std::vector<ASTUnit::RemappedFile> RemappedFiles;
29
29
for (const auto &P : Docs.getAllDocuments ()) {
30
30
StringRef FileName = P.first ;
31
- FileName.consume_front (" file://" );
32
31
RemappedFiles.push_back (ASTUnit::RemappedFile (
33
32
FileName,
34
33
llvm::MemoryBuffer::getMemBufferCopy (P.second , FileName).release ()));
@@ -142,7 +141,7 @@ void ASTManager::parseFileAndPublishDiagnostics(StringRef File) {
142
141
Diagnostics.pop_back (); // Drop trailing comma.
143
142
Output.writeMessage (
144
143
R"( {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":")" +
145
- File + R"( ","diagnostics":[)" + Diagnostics + R"( ]}})" );
144
+ URI::fromFile ( File). uri + R"( ","diagnostics":[)" + Diagnostics + R"( ]}})" );
146
145
}
147
146
148
147
ASTManager::~ASTManager () {
@@ -155,51 +154,48 @@ ASTManager::~ASTManager() {
155
154
ClangWorker.join ();
156
155
}
157
156
158
- void ASTManager::onDocumentAdd (StringRef Uri ) {
157
+ void ASTManager::onDocumentAdd (StringRef File ) {
159
158
if (RunSynchronously) {
160
- parseFileAndPublishDiagnostics (Uri );
159
+ parseFileAndPublishDiagnostics (File );
161
160
return ;
162
161
}
163
162
std::lock_guard<std::mutex> Guard (RequestLock);
164
163
// Currently we discard all pending requests and just enqueue the latest one.
165
164
RequestQueue.clear ();
166
- RequestQueue.push_back (Uri );
165
+ RequestQueue.push_back (File );
167
166
ClangRequestCV.notify_one ();
168
167
}
169
168
170
169
tooling::CompilationDatabase *
171
- ASTManager::getOrCreateCompilationDatabaseForFile (StringRef Uri ) {
172
- auto &I = CompilationDatabases[Uri ];
170
+ ASTManager::getOrCreateCompilationDatabaseForFile (StringRef File ) {
171
+ auto &I = CompilationDatabases[File ];
173
172
if (I)
174
173
return I.get ();
175
174
176
- Uri.consume_front (" file://" );
177
-
178
175
std::string Error;
179
- I = tooling::CompilationDatabase::autoDetectFromSource (Uri , Error);
176
+ I = tooling::CompilationDatabase::autoDetectFromSource (File , Error);
180
177
Output.log (" Failed to load compilation database: " + Twine (Error) + " \n " );
181
178
return I.get ();
182
179
}
183
180
184
181
std::unique_ptr<clang::ASTUnit>
185
- ASTManager::createASTUnitForFile (StringRef Uri , const DocumentStore &Docs) {
182
+ ASTManager::createASTUnitForFile (StringRef File , const DocumentStore &Docs) {
186
183
tooling::CompilationDatabase *CDB =
187
- getOrCreateCompilationDatabaseForFile (Uri );
184
+ getOrCreateCompilationDatabaseForFile (File );
188
185
189
- Uri.consume_front (" file://" );
190
186
std::vector<tooling::CompileCommand> Commands;
191
187
192
188
if (CDB) {
193
- Commands = CDB->getCompileCommands (Uri );
189
+ Commands = CDB->getCompileCommands (File );
194
190
// chdir. This is thread hostile.
195
191
if (!Commands.empty ())
196
192
llvm::sys::fs::set_current_path (Commands.front ().Directory );
197
193
}
198
194
if (Commands.empty ()) {
199
195
// Add a fake command line if we know nothing.
200
196
Commands.push_back (tooling::CompileCommand (
201
- llvm::sys::path::parent_path (Uri ), llvm::sys::path::filename (Uri ),
202
- {" clang" , " -fsyntax-only" , Uri .str ()}, " " ));
197
+ llvm::sys::path::parent_path (File ), llvm::sys::path::filename (File ),
198
+ {" clang" , " -fsyntax-only" , File .str ()}, " " ));
203
199
}
204
200
205
201
// Inject the resource dir.
@@ -278,7 +274,7 @@ class CompletionItemsCollector : public CodeCompleteConsumer {
278
274
} // namespace
279
275
280
276
std::vector<CompletionItem>
281
- ASTManager::codeComplete (StringRef Uri , unsigned Line, unsigned Column) {
277
+ ASTManager::codeComplete (StringRef File , unsigned Line, unsigned Column) {
282
278
CodeCompleteOptions CCO;
283
279
CCO.IncludeBriefComments = 1 ;
284
280
// This is where code completion stores dirty buffers. Need to free after
@@ -290,15 +286,13 @@ ASTManager::codeComplete(StringRef Uri, unsigned Line, unsigned Column) {
290
286
std::vector<CompletionItem> Items;
291
287
CompletionItemsCollector Collector (&Items, CCO);
292
288
std::lock_guard<std::mutex> Guard (ASTLock);
293
- auto &Unit = ASTs[Uri ];
289
+ auto &Unit = ASTs[File ];
294
290
if (!Unit)
295
- Unit = createASTUnitForFile (Uri , this ->Store );
291
+ Unit = createASTUnitForFile (File , this ->Store );
296
292
if (!Unit)
297
293
return {};
298
294
IntrusiveRefCntPtr<SourceManager> SourceMgr (
299
295
new SourceManager (*DiagEngine, Unit->getFileManager ()));
300
- StringRef File (Uri);
301
- File.consume_front (" file://" );
302
296
// CodeComplete seems to require fresh LangOptions.
303
297
LangOptions LangOpts = Unit->getLangOpts ();
304
298
// The language server protocol uses zero-based line and column numbers.
0 commit comments