@@ -117,7 +117,7 @@ llvm::Error validateEdits(const DraftStore &DraftMgr, const FileEdits &FE) {
117
117
// If the file is open in user's editor, make sure the version we
118
118
// saw and current version are compatible as this is the text that
119
119
// will be replaced by editors.
120
- if (!It.second .canApplyTo (* Draft)) {
120
+ if (!It.second .canApplyTo (Draft-> Contents )) {
121
121
++InvalidFileCount;
122
122
LastInvalidFile = It.first ();
123
123
}
@@ -630,7 +630,7 @@ void ClangdLSPServer::onDocumentDidOpen(
630
630
631
631
const std::string &Contents = Params.textDocument .text ;
632
632
633
- DraftMgr.addDraft (File, Contents);
633
+ DraftMgr.addDraft (File, Params. textDocument . version , Contents);
634
634
Server->addDocument (File, Contents, WantDiagnostics::Yes);
635
635
}
636
636
@@ -642,19 +642,19 @@ void ClangdLSPServer::onDocumentDidChange(
642
642
: WantDiagnostics::No;
643
643
644
644
PathRef File = Params.textDocument .uri .file ();
645
- llvm::Expected<std::string> Contents =
646
- DraftMgr. updateDraft ( File, Params.contentChanges );
647
- if (!Contents ) {
645
+ llvm::Expected<DraftStore::Draft> Draft = DraftMgr. updateDraft (
646
+ File, Params. textDocument . version , Params.contentChanges );
647
+ if (!Draft ) {
648
648
// If this fails, we are most likely going to be not in sync anymore with
649
649
// the client. It is better to remove the draft and let further operations
650
650
// fail rather than giving wrong results.
651
651
DraftMgr.removeDraft (File);
652
652
Server->removeDocument (File);
653
- elog (" Failed to update {0}: {1}" , File, Contents .takeError ());
653
+ elog (" Failed to update {0}: {1}" , File, Draft .takeError ());
654
654
return ;
655
655
}
656
656
657
- Server->addDocument (File, * Contents, WantDiags, Params.forceRebuild );
657
+ Server->addDocument (File, Draft-> Contents , WantDiags, Params.forceRebuild );
658
658
}
659
659
660
660
void ClangdLSPServer::onFileEvent (const DidChangeWatchedFilesParams &Params) {
@@ -773,8 +773,7 @@ void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
773
773
void ClangdLSPServer::onRename (const RenameParams &Params,
774
774
Callback<WorkspaceEdit> Reply) {
775
775
Path File = std::string (Params.textDocument .uri .file ());
776
- llvm::Optional<std::string> Code = DraftMgr.getDraft (File);
777
- if (!Code)
776
+ if (!DraftMgr.getDraft (File))
778
777
return Reply (llvm::make_error<LSPError>(
779
778
" onRename called for non-added file" , ErrorCode::InvalidParams));
780
779
Server->rename (
@@ -829,7 +828,7 @@ void ClangdLSPServer::onDocumentOnTypeFormatting(
829
828
" onDocumentOnTypeFormatting called for non-added file" ,
830
829
ErrorCode::InvalidParams));
831
830
832
- Reply (Server->formatOnType (* Code, File, Params.position , Params.ch ));
831
+ Reply (Server->formatOnType (Code-> Contents , File, Params.position , Params.ch ));
833
832
}
834
833
835
834
void ClangdLSPServer::onDocumentRangeFormatting (
@@ -842,9 +841,10 @@ void ClangdLSPServer::onDocumentRangeFormatting(
842
841
" onDocumentRangeFormatting called for non-added file" ,
843
842
ErrorCode::InvalidParams));
844
843
845
- auto ReplacementsOrError = Server->formatRange (*Code, File, Params.range );
844
+ auto ReplacementsOrError =
845
+ Server->formatRange (Code->Contents , File, Params.range );
846
846
if (ReplacementsOrError)
847
- Reply (replacementsToEdits (* Code, ReplacementsOrError.get ()));
847
+ Reply (replacementsToEdits (Code-> Contents , ReplacementsOrError.get ()));
848
848
else
849
849
Reply (ReplacementsOrError.takeError ());
850
850
}
@@ -859,9 +859,9 @@ void ClangdLSPServer::onDocumentFormatting(
859
859
" onDocumentFormatting called for non-added file" ,
860
860
ErrorCode::InvalidParams));
861
861
862
- auto ReplacementsOrError = Server->formatFile (* Code, File);
862
+ auto ReplacementsOrError = Server->formatFile (Code-> Contents , File);
863
863
if (ReplacementsOrError)
864
- Reply (replacementsToEdits (* Code, ReplacementsOrError.get ()));
864
+ Reply (replacementsToEdits (Code-> Contents , ReplacementsOrError.get ()));
865
865
else
866
866
Reply (ReplacementsOrError.takeError ());
867
867
}
@@ -1328,7 +1328,7 @@ bool ClangdLSPServer::shouldRunCompletion(
1328
1328
// Running the lexer here would be more robust (e.g. we can detect comments
1329
1329
// and avoid triggering completion there), but we choose to err on the side
1330
1330
// of simplicity here.
1331
- auto Offset = positionToOffset (* Code, Params.position ,
1331
+ auto Offset = positionToOffset (Code-> Contents , Params.position ,
1332
1332
/* AllowColumnsBeyondLineLength=*/ false );
1333
1333
if (!Offset) {
1334
1334
vlog (" could not convert position '{0}' to offset for file '{1}'" ,
@@ -1339,9 +1339,9 @@ bool ClangdLSPServer::shouldRunCompletion(
1339
1339
return false ;
1340
1340
1341
1341
if (Trigger == " >" )
1342
- return (* Code) [*Offset - 2 ] == ' -' ; // trigger only on '->'.
1342
+ return Code-> Contents [*Offset - 2 ] == ' -' ; // trigger only on '->'.
1343
1343
if (Trigger == " :" )
1344
- return (* Code) [*Offset - 2 ] == ' :' ; // trigger only on '::'.
1344
+ return Code-> Contents [*Offset - 2 ] == ' :' ; // trigger only on '::'.
1345
1345
assert (false && " unhandled trigger character" );
1346
1346
return true ;
1347
1347
}
@@ -1475,7 +1475,7 @@ void ClangdLSPServer::reparseOpenedFiles(
1475
1475
// Reparse only opened files that were modified.
1476
1476
for (const Path &FilePath : DraftMgr.getActiveFiles ())
1477
1477
if (ModifiedFiles.find (FilePath) != ModifiedFiles.end ())
1478
- Server->addDocument (FilePath, * DraftMgr.getDraft (FilePath),
1478
+ Server->addDocument (FilePath, DraftMgr.getDraft (FilePath)-> Contents ,
1479
1479
WantDiagnostics::Auto);
1480
1480
}
1481
1481
0 commit comments