Skip to content

Commit 32710f2

Browse files
committed
Initialize file versions from didOpen argument
Before this patch, the language server initialized versions of all newly opened file to 1. However, the language server protocol defines a parameter for didOpen that says that the client gets to decide the initial versions of opened files. One client, namely Helix 25.1, passes an initial value of 0 which caused e.g. renaming a variable right after opening a file to fail. This patch makes the initial value of versions the one that's passed by the client.
1 parent e93b107 commit 32710f2

File tree

13 files changed

+47
-36
lines changed

13 files changed

+47
-36
lines changed

source/ada/lsp-ada_documents.adb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,10 @@ package body LSP.Ada_Documents is
13291329
(Self : in out Document;
13301330
Handler : LSP.Ada_Handlers.Message_Handler'Class;
13311331
URI : LSP.Structures.DocumentUri;
1332-
Text : VSS.Strings.Virtual_String) is
1332+
Text : VSS.Strings.Virtual_String;
1333+
Version : Integer) is
13331334
begin
1334-
LSP.Text_Documents.Constructors.Initialize (Self, URI, Text);
1335+
LSP.Text_Documents.Constructors.Initialize (Self, URI, Text, Version);
13351336

13361337
Self.Refresh_Symbol_Cache := True;
13371338
Self.Diagnostic_Sources.Append

source/ada/lsp-ada_documents.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ package LSP.Ada_Documents is
5555
(Self : in out Document;
5656
Handler : LSP.Ada_Handlers.Message_Handler'Class;
5757
URI : LSP.Structures.DocumentUri;
58-
Text : VSS.Strings.Virtual_String);
58+
Text : VSS.Strings.Virtual_String;
59+
Version : Integer);
5960
-- Create a new document from a TextDocumentItem.
6061

6162
procedure Cleanup (Self : in out Document);

source/ada/lsp-ada_handlers.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,8 @@ package body LSP.Ada_Handlers is
20292029
Project_Loading.Ensure_Project_Loaded (Self);
20302030

20312031
-- We have received a document: add it to the documents container
2032-
Object.Initialize (Self, URI, Value.textDocument.text);
2032+
Object.Initialize
2033+
(Self, URI, Value.textDocument.text, Value.textDocument.version);
20332034
Self.Open_Documents.Include (File, Object);
20342035

20352036
-- Handle the case where we're loading the implicit project: do

source/gpr/lsp-gpr_documents.adb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,14 @@ package body LSP.GPR_Documents is
147147
----------------
148148

149149
procedure Initialize
150-
(Self : in out Document;
151-
URI : LSP.Structures.DocumentUri;
152-
File : GPR2.Path_Name.Object;
153-
Text : VSS.Strings.Virtual_String;
154-
Provider : LSP.GPR_Files.File_Provider_Access) is
150+
(Self : in out Document;
151+
URI : LSP.Structures.DocumentUri;
152+
File : GPR2.Path_Name.Object;
153+
Text : VSS.Strings.Virtual_String;
154+
Provider : LSP.GPR_Files.File_Provider_Access;
155+
Version : Integer) is
155156
begin
156-
LSP.Text_Documents.Constructors.Initialize (Self, URI, Text);
157+
LSP.Text_Documents.Constructors.Initialize (Self, URI, Text, Version);
157158

158159
Self.File := File;
159160
Self.File_Provider := Provider;

source/gpr/lsp-gpr_documents.ads

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ package LSP.GPR_Documents is
6565
-- Used to split a tree's log into logs (one for each file with message)
6666

6767
procedure Initialize
68-
(Self : in out Document;
69-
URI : LSP.Structures.DocumentUri;
70-
File : GPR2.Path_Name.Object;
71-
Text : VSS.Strings.Virtual_String;
72-
Provider : LSP.GPR_Files.File_Provider_Access);
68+
(Self : in out Document;
69+
URI : LSP.Structures.DocumentUri;
70+
File : GPR2.Path_Name.Object;
71+
Text : VSS.Strings.Virtual_String;
72+
Provider : LSP.GPR_Files.File_Provider_Access;
73+
Version : Integer);
7374
-- Create a new document from a TextDocumentItem. Use Diagnostic as
7475
-- project status diagnostic source.
7576

source/gpr/lsp-gpr_handlers.adb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ package body LSP.GPR_Handlers is
214214

215215
-- We have received a document: add it to the documents container
216216
Object.Initialize
217-
(URI, GPR2.Path_Name.Create (Self.To_File (URI)),
218-
Value.textDocument.text, Self'Unchecked_Access);
217+
(URI,
218+
GPR2.Path_Name.Create (Self.To_File (URI)),
219+
Value.textDocument.text,
220+
Self'Unchecked_Access,
221+
Value.textDocument.version);
219222

220223
Self.Open_Documents.Include (File, Object);
221224

source/server/lsp-text_documents.adb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,14 @@ package body LSP.Text_Documents is
147147
----------------
148148

149149
procedure Initialize
150-
(Self : in out Text_Document'Class;
151-
URI : LSP.Structures.DocumentUri;
152-
Text : VSS.Strings.Virtual_String) is
150+
(Self : in out Text_Document'Class;
151+
URI : LSP.Structures.DocumentUri;
152+
Text : VSS.Strings.Virtual_String;
153+
Version : Integer) is
153154
begin
154155
Self.URI := URI;
155156
Self.Text := Text;
157+
Self.Version := Version;
156158

157159
Self.Recompute_Indexes;
158160
end Initialize;

source/server/lsp-text_documents.ads

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ package LSP.Text_Documents is
9595
package Constructors is
9696

9797
procedure Initialize
98-
(Self : in out Text_Document'Class;
99-
URI : LSP.Structures.DocumentUri;
100-
Text : VSS.Strings.Virtual_String);
98+
(Self : in out Text_Document'Class;
99+
URI : LSP.Structures.DocumentUri;
100+
Text : VSS.Strings.Virtual_String;
101+
Version : Integer);
101102

102103
end Constructors;
103104

testsuite/ada_lsp/Did_Rename_Files.context_corruption/test.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
{
258258
"textDocument": {
259259
"uri": "$URI{foo-bar1.ads}",
260-
"version": 1
260+
"version": 0
261261
},
262262
"edits": [
263263
{
@@ -293,7 +293,7 @@
293293
{
294294
"textDocument": {
295295
"uri": "$URI{main.adb}",
296-
"version": 1
296+
"version": 0
297297
},
298298
"edits": [
299299
{

testsuite/ada_lsp/SC28-001.named.parameters.0/SC28-001.named.parameters.0.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
{
249249
"textDocument": {
250250
"uri": "$URI{main.adb}",
251-
"version": 1
251+
"version": 0
252252
},
253253
"edits": [
254254
{
@@ -308,7 +308,7 @@
308308
{
309309
"textDocument": {
310310
"uri": "$URI{main.adb}",
311-
"version": 1
311+
"version": 0
312312
},
313313
"edits": [
314314
{
@@ -368,7 +368,7 @@
368368
{
369369
"textDocument": {
370370
"uri": "$URI{main.adb}",
371-
"version": 1
371+
"version": 0
372372
},
373373
"edits": [
374374
{
@@ -428,7 +428,7 @@
428428
{
429429
"textDocument": {
430430
"uri": "$URI{main.adb}",
431-
"version": 1
431+
"version": 0
432432
},
433433
"edits": [
434434
{
@@ -488,7 +488,7 @@
488488
{
489489
"textDocument": {
490490
"uri": "$URI{main.adb}",
491-
"version": 1
491+
"version": 0
492492
},
493493
"edits": [
494494
{
@@ -548,7 +548,7 @@
548548
{
549549
"textDocument": {
550550
"uri": "$URI{main.adb}",
551-
"version": 1
551+
"version": 0
552552
},
553553
"edits": [
554554
{
@@ -608,7 +608,7 @@
608608
{
609609
"textDocument": {
610610
"uri": "$URI{main.adb}",
611-
"version": 1
611+
"version": 0
612612
},
613613
"edits": [
614614
{
@@ -668,7 +668,7 @@
668668
{
669669
"textDocument": {
670670
"uri": "$URI{main.adb}",
671-
"version": 1
671+
"version": 0
672672
},
673673
"edits": [
674674
{

0 commit comments

Comments
 (0)