@@ -74,60 +74,14 @@ VirtualFileSystem::UpdateFile(std::string_view uri, std::vector<lsp::TextDocumen
7474 return ;
7575 }
7676 auto fileId = opFileId.value ();
77- auto opSourceText = _fileDB.Query (fileId);
78- if (!opSourceText.has_value ()) {
79- return ;
80- }
81- auto &sourceText = *opSourceText.value ();
82-
83- auto vFile = VirtualFile (fileId);
84- auto lineIndex = vFile.GetLineIndex (*this );
85- if (!lineIndex) {
86- return ;
87- }
8877
89- std::string text;
90- auto totalSize = sourceText.size ();
91- std::vector<std::pair<TextRange, std::string>> textChanges;
9278 for (auto &change: changeEvent) {
9379 if (!change.range .has_value ()) {
9480 return ;
9581 }
9682 auto range = change.range .value ();
97- auto &content = change.text ;
98- auto startOffset = lineIndex->GetOffset (LineCol (range.start .line , range.start .character ));
99- auto endOffset = lineIndex->GetOffset (LineCol (range.end .line , range.end .character ));
100- textChanges.emplace_back (TextRange (startOffset, endOffset), std::move (content));
101- totalSize += content.size () - (endOffset - startOffset);
83+ UpdateFile (fileId, range, std::move (change.text ));
10284 }
103-
104- std::stable_sort (textChanges.begin (), textChanges.end (), [](auto &x, auto &y) -> bool {
105- return x.first .StartOffset < y.first .StartOffset ;
106- });
107-
108- if (totalSize > 0 ) {
109- text.reserve (totalSize);
110- std::size_t start = 0 ;
111- for (std::size_t index = 0 ; index != textChanges.size (); index++) {
112- auto textRange = textChanges[index].first ;
113- if (start < textRange.StartOffset ) {
114- text.append (sourceText.begin () + start, sourceText.begin () + textRange.StartOffset );
115- }
116-
117- auto &content = textChanges[index].second ;
118-
119- text.append (content);
120-
121- start = textChanges[index].first .EndOffset ;
122- }
123-
124- if (start < sourceText.size ()) {
125- text.append (sourceText.begin () + start, sourceText.end ());
126- }
127- }
128-
129- lineIndex->Parse (text);
130- _fileDB.ApplyFileUpdate (fileId, std::move (text));
13185}
13286
13387void VirtualFileSystem::ClearFile (std::string_view uri) {
0 commit comments