@@ -35,4 +35,40 @@ describe("DocumentRegistry", () => {
35
35
36
36
assert ( f3 === f4 , "Changed module: Expected to have the same instance of the document" ) ;
37
37
} ) ;
38
+
39
+ it ( "Acquiring document gets correct version 1" , ( ) => {
40
+ var documentRegistry = ts . createDocumentRegistry ( ) ;
41
+ var defaultCompilerOptions = ts . getDefaultCompilerOptions ( ) ;
42
+
43
+ // Simulate one LS getting the document.
44
+ var f1 = documentRegistry . acquireDocument ( "file1.ts" , defaultCompilerOptions , ts . ScriptSnapshot . fromString ( "var x = 1;" ) , /* version */ "1" ) ;
45
+
46
+ // Simulate another LS getting the document at another version.
47
+ var f2 = documentRegistry . acquireDocument ( "file1.ts" , defaultCompilerOptions , ts . ScriptSnapshot . fromString ( "var x = 1;" ) , /* version */ "2" ) ;
48
+
49
+ assert ( f2 . version === "2" ) ;
50
+ } ) ;
51
+
52
+ it ( "Acquiring document gets correct version 2" , ( ) => {
53
+ debugger ;
54
+ var documentRegistry = ts . createDocumentRegistry ( ) ;
55
+ var defaultCompilerOptions = ts . getDefaultCompilerOptions ( ) ;
56
+
57
+ var contents = "var x = 1;"
58
+ var snapshot = ts . ScriptSnapshot . fromString ( contents ) ;
59
+
60
+ // Simulate one LS getting the document.
61
+ var f1 = documentRegistry . acquireDocument ( "file1.ts" , defaultCompilerOptions , snapshot , /* version */ "1" ) ;
62
+
63
+ // Simulate another LS getting that document.
64
+ var f2 = documentRegistry . acquireDocument ( "file1.ts" , defaultCompilerOptions , snapshot , /* version */ "1" ) ;
65
+
66
+ // Now LS1 updates their document.
67
+ var f3 = documentRegistry . updateDocument ( f1 , "file1.ts" , defaultCompilerOptions , snapshot , /* version */ "2" ,
68
+ ts . createTextChangeRange ( ts . createTextSpan ( 0 , contents . length ) , contents . length ) ) ;
69
+
70
+ // Now LS2 tries to update their document.
71
+ var f4 = documentRegistry . updateDocument ( f1 , "file1.ts" , defaultCompilerOptions , snapshot , /* version */ "3" ,
72
+ ts . createTextChangeRange ( ts . createTextSpan ( 0 , contents . length ) , contents . length ) ) ;
73
+ } ) ;
38
74
} ) ;
0 commit comments