@volar/language-server 1.2.0-alpha.9 → 1.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import { FileSystemHost } from '../types';
2
- export declare function createWebFileSystemHost(): FileSystemHost;
1
+ import { FileSystemHost, LanguageServerInitializationOptions, RuntimeEnvironment } from '../types';
2
+ export declare function createWebFileSystemHost(_0: any, _1: any, env: RuntimeEnvironment, initOptions: LanguageServerInitializationOptions): FileSystemHost;
@@ -16,53 +16,53 @@ const vscode_uri_1 = require("vscode-uri");
16
16
  const protocol_1 = require("../protocol");
17
17
  const utilities_1 = require("./typescript/utilities");
18
18
  const uriMap_1 = require("../common/utils/uriMap");
19
- const shared = require("@volar/shared");
20
19
  let currentCwd = '/';
21
- function createWebFileSystemHost() {
22
- const instances = (0, uriMap_1.createUriMap)();
20
+ function createWebFileSystemHost(_0, _1, env, initOptions) {
21
+ const instances = (0, uriMap_1.createUriMap)(env.fileNameToUri);
23
22
  const onDidChangeWatchedFilesCb = new Set();
24
23
  const root = {
25
24
  dirs: new Map(),
26
- fileTexts: new Map(),
27
- fileTypes: new Map(),
28
- searched: false,
25
+ files: new Map(),
26
+ requested: false,
29
27
  };
30
- const pendings = [];
28
+ const fetchTasks = [];
31
29
  const changes = [];
32
- const onReadys = [];
33
- let loading = false;
30
+ const onReadyCb = [];
31
+ let runningRead = false;
32
+ let runningStat = false;
34
33
  let connection;
35
34
  return {
36
35
  ready(_connection) {
37
36
  connection = _connection;
38
37
  connection.onDidChangeWatchedFiles(params => {
39
38
  for (const change of params.changes) {
40
- const fsPath = shared.uriToFileName(change.uri);
39
+ const fsPath = env.uriToFileName(change.uri);
41
40
  const dir = getDir(path.dirname(fsPath));
42
41
  const name = path.basename(fsPath);
43
- if (change.type === vscode.FileChangeType.Created) {
44
- dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
42
+ if (!dir.files.has(name)) {
43
+ dir.files.set(name, {});
45
44
  }
46
- else if (change.type === vscode.FileChangeType.Changed) {
47
- dir.fileTexts.delete(name);
45
+ if (change.type === vscode.FileChangeType.Created || change.type === vscode.FileChangeType.Changed) {
46
+ dir.files.get(name).exists = true;
48
47
  }
49
- else {
50
- dir.fileTypes.delete(name);
51
- dir.fileTexts.delete(name);
48
+ else if (change.type === vscode.FileChangeType.Deleted) {
49
+ if (!dir.files.has(name)) {
50
+ dir.files.set(name, {});
51
+ }
52
52
  }
53
53
  }
54
- fireChanges(params);
54
+ changes.push(...params.changes);
55
+ fireChanges();
55
56
  });
56
- for (const cb of onReadys) {
57
+ for (const cb of onReadyCb) {
57
58
  cb(connection);
58
59
  }
59
- onReadys.length = 0;
60
+ onReadyCb.length = 0;
60
61
  },
61
62
  reload() {
62
63
  root.dirs.clear();
63
- root.fileTexts.clear();
64
- root.fileTypes.clear();
65
- root.searched = false;
64
+ root.files.clear();
65
+ root.requested = false;
66
66
  },
67
67
  getWorkspaceFileSystem(rootUri) {
68
68
  let sys = instances.uriGet(rootUri.toString());
@@ -78,11 +78,11 @@ function createWebFileSystemHost() {
78
78
  },
79
79
  };
80
80
  function createWorkspaceFileSystem(rootUri) {
81
- const rootPath = shared.uriToFileName(rootUri.toString());
81
+ const rootPath = env.uriToFileName(rootUri.toString());
82
82
  return {
83
83
  newLine: '\n',
84
84
  useCaseSensitiveFileNames: false,
85
- getCurrentDirectory: () => shared.uriToFileName(rootUri.toString()),
85
+ getCurrentDirectory: () => env.uriToFileName(rootUri.toString()),
86
86
  fileExists,
87
87
  readFile,
88
88
  readDirectory,
@@ -98,183 +98,175 @@ function createWebFileSystemHost() {
98
98
  return path.resolve(fsPath);
99
99
  }
100
100
  function fileExists(fsPath) {
101
+ var _a, _b, _c;
101
102
  fsPath = resolvePath(fsPath);
102
- const dir = getDir(path.dirname(fsPath));
103
- const name = path.basename(fsPath);
104
- if (dir.fileTypes.has(name)) {
105
- return dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.File || dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.SymbolicLink;
106
- }
107
- dir.fileTypes.set(name, undefined);
108
- if (connection) {
109
- addPending('Stat', fsPath, statAsync(connection, fsPath, dir));
110
- }
111
- else {
112
- onReadys.push((connection) => addPending('Stat', fsPath, statAsync(connection, fsPath, dir)));
103
+ const uri = env.fileNameToUri(fsPath);
104
+ const dirPath = path.dirname(fsPath);
105
+ if (((_a = initOptions.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(initOptions.typescript.cdn)) {
106
+ if (!(uri.endsWith('.d.ts') || uri.endsWith('/package.json'))) {
107
+ return false;
108
+ }
109
+ readFile(fsPath);
110
+ const file = getDir(dirPath).files.get(path.basename(fsPath));
111
+ return (_b = file === null || file === void 0 ? void 0 : file.exists) !== null && _b !== void 0 ? _b : false;
113
112
  }
114
- return false;
113
+ readDirectory(dirPath);
114
+ const file = getDir(path.dirname(fsPath)).files.get(path.basename(fsPath));
115
+ return (_c = file === null || file === void 0 ? void 0 : file.exists) !== null && _c !== void 0 ? _c : false;
115
116
  }
116
117
  function readFile(fsPath) {
118
+ var _a, _b, _c, _d;
117
119
  fsPath = resolvePath(fsPath);
118
- const dir = getDir(path.dirname(fsPath));
120
+ const uri = env.fileNameToUri(fsPath);
121
+ const dirPath = path.dirname(fsPath);
122
+ const dir = getDir(dirPath);
119
123
  const name = path.basename(fsPath);
120
- if (dir.fileTexts.has(name)) {
121
- return dir.fileTexts.get(name);
124
+ if (((_a = initOptions.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(initOptions.typescript.cdn)) {
125
+ if (!(uri.endsWith('.d.ts') || uri.endsWith('/package.json'))) {
126
+ return ((_b = dir.files.get(name)) === null || _b === void 0 ? void 0 : _b.text) || '';
127
+ }
128
+ readFileWorker();
129
+ return ((_c = dir.files.get(name)) === null || _c === void 0 ? void 0 : _c.text) || '';
122
130
  }
123
- dir.fileTexts.set(name, '');
124
- if (connection) {
125
- addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir));
131
+ readFileWorker();
132
+ return ((_d = dir.files.get(name)) === null || _d === void 0 ? void 0 : _d.text) || '';
133
+ function readFileWorker() {
134
+ if (connection) {
135
+ fetch('load', fsPath, readFileAsync(connection, fsPath, dir));
136
+ }
137
+ else {
138
+ onReadyCb.push((connection) => fetch('load', fsPath, readFileAsync(connection, fsPath, dir)));
139
+ }
126
140
  }
127
- else {
128
- onReadys.push((connection) => addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir)));
141
+ function readFileAsync(connection, fsPath, dir) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ const name = path.basename(fsPath);
144
+ if (!dir.files.has(name)) {
145
+ dir.files.set(name, {});
146
+ }
147
+ const file = dir.files.get(name);
148
+ if (file.requested) {
149
+ return;
150
+ }
151
+ file.requested = true;
152
+ const uri = env.fileNameToUri(fsPath);
153
+ const data = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, resolveRequestUrl(uri));
154
+ const text = data ? new TextDecoder('utf8').decode(data) : undefined;
155
+ if (text === null || text === void 0 ? void 0 : text.length) {
156
+ file.exists = true;
157
+ file.text = text;
158
+ changes.push({ uri, type: vscode.FileChangeType.Changed });
159
+ }
160
+ });
129
161
  }
130
- return '';
131
162
  }
132
163
  function readDirectory(fsPath, extensions, exclude, include, depth) {
133
164
  fsPath = resolvePath(fsPath);
134
- return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootPath, depth, _dirPath => {
135
- let dirPath = _dirPath;
165
+ return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootPath, depth, (dirPath) => {
136
166
  dirPath = resolvePath(dirPath);
167
+ readDirectoryWorker(dirPath);
137
168
  const dir = getDir(dirPath);
138
- const files = [...dir.fileTypes];
139
- if (!dir.searched) {
140
- dir.searched = true;
141
- if (connection) {
142
- addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir));
143
- }
144
- else {
145
- onReadys.push((connection) => addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir)));
146
- }
147
- }
148
169
  return {
149
- files: files.filter(file => file[1] === vscode_html_languageservice_1.FileType.File).map(file => file[0]),
150
- directories: files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]),
170
+ files: [...dir.files.entries()].filter(([_, file]) => file.exists).map(([name]) => name),
171
+ directories: [...dir.dirs.entries()].filter(([_, dir]) => dir.exists).map(([name]) => name),
151
172
  };
152
173
  }, path => path);
153
174
  }
154
175
  // for import path completion
155
176
  function getDirectories(fsPath) {
156
177
  fsPath = resolvePath(fsPath);
178
+ readDirectoryWorker(fsPath);
157
179
  const dir = getDir(fsPath);
158
- const files = [...dir.fileTypes];
159
- if (!dir.searched) {
160
- dir.searched = true;
161
- if (connection) {
162
- addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir));
163
- }
164
- else {
165
- onReadys.push((connection) => addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir)));
166
- }
167
- }
168
- return files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]);
180
+ return [...dir.dirs.entries()].filter(([_, dir]) => dir.exists).map(([name]) => name);
169
181
  }
170
- function statAsync(connection, fsPath, dir) {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- const uri = shared.fileNameToUri(fsPath);
173
- if (uri.startsWith('https://unpkg.com/')) { // stat request always response file type for jsdelivr
174
- const text = yield readWebFile(connection, uri);
175
- if (text !== undefined) {
176
- const name = path.basename(fsPath);
177
- dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
178
- dir.fileTexts.set(name, text);
179
- changes.push({
180
- uri: uri,
181
- type: vscode.FileChangeType.Created,
182
- });
183
- }
184
- }
185
- else {
186
- const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri);
187
- if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) {
188
- const name = path.basename(fsPath);
189
- dir.fileTypes.set(name, result.type);
190
- changes.push({
191
- uri: uri,
192
- type: vscode.FileChangeType.Created,
193
- });
194
- }
195
- }
196
- });
197
- }
198
- function readFileAsync(connection, fsPath, dir) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- const uri = shared.fileNameToUri(fsPath);
201
- if (uri.startsWith('https://unpkg.com/')) {
202
- const text = yield readWebFile(connection, uri);
203
- if (text !== undefined) {
204
- const name = path.basename(fsPath);
205
- dir.fileTexts.set(name, text);
206
- changes.push({
207
- uri: uri,
208
- type: vscode.FileChangeType.Changed,
209
- });
210
- }
211
- }
212
- else {
213
- const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri);
214
- if (text) {
215
- const name = path.basename(fsPath);
216
- dir.fileTexts.set(name, text);
217
- changes.push({
218
- uri: uri,
219
- type: vscode.FileChangeType.Changed,
220
- });
221
- }
222
- }
223
- });
182
+ function readDirectoryWorker(fsPath) {
183
+ if (connection) {
184
+ fetch('directory', fsPath, readDirectoryAsync(connection, fsPath));
185
+ }
186
+ else {
187
+ onReadyCb.push((connection) => fetch('directory', fsPath, readDirectoryAsync(connection, fsPath)));
188
+ }
224
189
  }
225
- function readWebFile(connection, uri) {
226
- var _a;
190
+ function readDirectoryAsync(connection, fsPath) {
227
191
  return __awaiter(this, void 0, void 0, function* () {
228
- // ignore .js because it's no help for intellisense
229
- if (uri.endsWith('.d.ts') || uri.endsWith('.json')) {
230
- return (_a = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri)) !== null && _a !== void 0 ? _a : undefined;
192
+ const dir = getDir(fsPath);
193
+ if (dir.requested) {
194
+ return;
231
195
  }
232
- });
233
- }
234
- function readDirectoryAsync(connection, fsPath, dir) {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- const uri = shared.fileNameToUri(fsPath);
237
- const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, uri);
196
+ dir.requested = true;
197
+ const uri = env.fileNameToUri(fsPath);
198
+ const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, resolveRequestUrl(uri));
238
199
  for (const [name, fileType] of result) {
239
- if (dir.fileTypes.get(name) !== fileType && (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink)) {
240
- changes.push({
241
- uri: shared.fileNameToUri(path.join(fsPath, name)),
242
- type: vscode.FileChangeType.Created,
243
- });
200
+ if (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink) {
201
+ if (!dir.files.has(name)) {
202
+ dir.files.set(name, {});
203
+ }
204
+ const file = dir.files.get(name);
205
+ if (!file.exists) {
206
+ file.exists = true;
207
+ changes.push({
208
+ uri: env.fileNameToUri(path.join(fsPath, name)),
209
+ type: vscode.FileChangeType.Created,
210
+ });
211
+ }
212
+ }
213
+ else if (fileType === vscode_html_languageservice_1.FileType.Directory && !dir.dirs.has(name)) {
214
+ const childDir = getDirFromDir(dir, name);
215
+ childDir.exists = true;
244
216
  }
245
- dir.fileTypes.set(name, fileType);
246
217
  }
247
218
  });
248
219
  }
249
220
  }
250
- function addPending(action, fileName, p) {
221
+ function fetch(action, fileName, p) {
251
222
  return __awaiter(this, void 0, void 0, function* () {
252
- pendings.push([action, fileName, p]);
253
- if (loading === false) {
254
- loading = true;
223
+ fetchTasks.push([action, fileName, p]);
224
+ if (runningRead === false) {
225
+ let toUpdate;
226
+ runningRead = true;
255
227
  const progress = yield (connection === null || connection === void 0 ? void 0 : connection.window.createWorkDoneProgress());
256
- progress === null || progress === void 0 ? void 0 : progress.begin(action);
257
- let i = 0;
258
- while (pendings.length) {
259
- const current = pendings.shift();
260
- progress === null || progress === void 0 ? void 0 : progress.report(i / pendings.length, vscode_uri_1.URI.parse(shared.fileNameToUri(current[1])).fsPath);
228
+ progress === null || progress === void 0 ? void 0 : progress.begin('');
229
+ while (fetchTasks.length) {
230
+ const current = fetchTasks.shift();
231
+ updateProgress(current[0] + ' ' + vscode_uri_1.URI.parse(env.fileNameToUri(current[1])).fsPath);
261
232
  yield current[2];
262
- i++;
263
233
  }
264
234
  progress === null || progress === void 0 ? void 0 : progress.done();
265
- if (changes.length) {
266
- fireChanges({ changes: [...changes] });
267
- changes.length = 0;
235
+ runningRead = false;
236
+ fireChanges();
237
+ function updateProgress(text) {
238
+ clearTimeout(toUpdate);
239
+ toUpdate = setTimeout(() => {
240
+ progress === null || progress === void 0 ? void 0 : progress.report(text);
241
+ toUpdate = undefined;
242
+ }, 0);
268
243
  }
269
- loading = false;
270
244
  }
271
245
  });
272
246
  }
273
- function fireChanges(params) {
247
+ function resolveRequestUrl(uri) {
248
+ var _a;
249
+ if (((_a = initOptions.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(initOptions.typescript.cdn)) {
250
+ let fileName = env.uriToFileName(uri);
251
+ for (const [key, version] of Object.entries(initOptions.typescript.versions || {})) {
252
+ if (fileName.startsWith(`/node_modules/${key}/`)) {
253
+ fileName = fileName.replace(`/node_modules/${key}/`, `/node_modules/${key}@${version}/`);
254
+ return env.fileNameToUri(fileName);
255
+ }
256
+ }
257
+ }
258
+ return uri;
259
+ }
260
+ function fireChanges() {
274
261
  return __awaiter(this, void 0, void 0, function* () {
262
+ if (runningRead || runningStat) {
263
+ return;
264
+ }
265
+ const _changes = [...changes];
266
+ changes.length = 0;
275
267
  for (const cb of [...onDidChangeWatchedFilesCb]) {
276
268
  if (onDidChangeWatchedFilesCb.has(cb)) {
277
- yield cb(params);
269
+ yield cb({ changes: _changes });
278
270
  }
279
271
  }
280
272
  });
@@ -300,9 +292,7 @@ function createWebFileSystemHost() {
300
292
  if (!target) {
301
293
  target = {
302
294
  dirs: new Map(),
303
- fileTexts: new Map(),
304
- fileTypes: new Map(),
305
- searched: false,
295
+ files: new Map(),
306
296
  };
307
297
  dir.dirs.set(name, target);
308
298
  }
@@ -28,7 +28,7 @@ const vscode = require("vscode-languageserver/browser");
28
28
  const server_1 = require("../common/server");
29
29
  const http_1 = require("../common/schemaRequestHandlers/http");
30
30
  const fileSystems_1 = require("./fileSystems");
31
- const shared = require("@volar/shared");
31
+ const vscode_uri_1 = require("vscode-uri");
32
32
  __exportStar(require("../index"), exports);
33
33
  function createConnection() {
34
34
  const messageReader = new vscode.BrowserMessageReader(self);
@@ -38,39 +38,71 @@ function createConnection() {
38
38
  }
39
39
  exports.createConnection = createConnection;
40
40
  function startLanguageServer(connection, ...plugins) {
41
- (0, server_1.startCommonLanguageServer)({
42
- plugins,
43
- connection,
44
- runtimeEnv: {
45
- timer: {
46
- setImmediate(callback, ...args) {
47
- const handle = setTimeout(callback, 0, ...args);
48
- return { dispose: () => clearTimeout(handle) };
41
+ (0, server_1.startCommonLanguageServer)(connection, options => {
42
+ return {
43
+ plugins,
44
+ connection,
45
+ runtimeEnv: {
46
+ uriToFileName,
47
+ fileNameToUri,
48
+ timer: {
49
+ setImmediate(callback, ...args) {
50
+ const handle = setTimeout(callback, 0, ...args);
51
+ return { dispose: () => clearTimeout(handle) };
52
+ },
49
53
  },
54
+ loadTypescript() {
55
+ return require('typescript'); // force bundle because not support load by user config in web
56
+ },
57
+ loadTypescriptLocalized(tsdk, locale) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ try {
60
+ const uri = fileNameToUri(`${tsdk}/${locale}/diagnosticMessages.generated.json`);
61
+ const json = yield (0, http_1.default)(uri);
62
+ if (json) {
63
+ return JSON.parse(json);
64
+ }
65
+ }
66
+ catch (_a) { }
67
+ });
68
+ },
69
+ schemaRequestHandlers: {
70
+ http: http_1.default,
71
+ https: http_1.default,
72
+ },
73
+ onDidChangeConfiguration(settings) {
74
+ (0, request_light_1.configure)(settings.http && settings.http.proxy, settings.http && settings.http.proxyStrictSSL);
75
+ },
76
+ fileSystemProvide: undefined,
77
+ createFileSystemHost: fileSystems_1.createWebFileSystemHost,
50
78
  },
51
- loadTypescript() {
52
- return require('typescript'); // force bundle because not support load by user config in web
53
- },
54
- loadTypescriptLocalized(tsdk, locale) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- try {
57
- const uri = shared.fileNameToUri(`${tsdk}/${locale}/diagnosticMessages.generated.json`);
58
- const json = yield (0, http_1.default)(uri);
59
- return JSON.parse(json);
60
- }
61
- catch (_a) { }
62
- });
63
- },
64
- schemaRequestHandlers: {
65
- http: http_1.default,
66
- https: http_1.default,
67
- },
68
- onDidChangeConfiguration(settings) {
69
- (0, request_light_1.configure)(settings.http && settings.http.proxy, settings.http && settings.http.proxyStrictSSL);
70
- },
71
- fileSystemProvide: undefined,
72
- createFileSystemHost: fileSystems_1.createWebFileSystemHost,
73
- },
79
+ };
80
+ function uriToFileName(uri) {
81
+ var _a;
82
+ const parsed = vscode_uri_1.URI.parse(uri);
83
+ if (((_a = options.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(options.typescript.cdn)) {
84
+ return parsed.toString(true).replace(options.typescript.cdn, '/node_modules/');
85
+ }
86
+ return `/${parsed.scheme}${parsed.authority ? '@' + parsed.authority : ''}${parsed.path}`;
87
+ }
88
+ ;
89
+ function fileNameToUri(fileName) {
90
+ var _a;
91
+ if (fileName.startsWith('/node_modules/') && ((_a = options.typescript) === null || _a === void 0 ? void 0 : _a.cdn)) {
92
+ return vscode_uri_1.URI.parse(fileName.replace('/node_modules/', options.typescript.cdn)).toString();
93
+ }
94
+ const parts = fileName.split('/');
95
+ if (parts.length <= 1) {
96
+ return vscode_uri_1.URI.from({ scheme: '', path: '' }).toString();
97
+ }
98
+ const firstParts = parts[1].split('@');
99
+ return vscode_uri_1.URI.from({
100
+ scheme: firstParts[0],
101
+ authority: firstParts.length > 1 ? firstParts[1] : undefined,
102
+ path: '/' + parts.slice(2).join('/'),
103
+ }).toString();
104
+ }
105
+ ;
74
106
  });
75
107
  }
76
108
  exports.startLanguageServer = startLanguageServer;
@@ -1,6 +1,7 @@
1
1
  import { TextDocument } from 'vscode-languageserver-textdocument';
2
2
  import * as vscode from 'vscode-languageserver';
3
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
+ import { RuntimeEnvironment } from '../types';
4
5
  interface IncrementalScriptSnapshotChange {
5
6
  applied: boolean;
6
7
  changeRange: ts.TextChangeRange | undefined;
@@ -25,7 +26,7 @@ declare class IncrementalScriptSnapshot {
25
26
  applyVersionChanges(version: number, removeBeforeVersions: boolean): void;
26
27
  }
27
28
  export declare function combineContinuousChangeRanges(...changeRanges: ts.TextChangeRange[]): ts.TextChangeRange;
28
- export declare function createDocuments(connection: vscode.Connection): {
29
+ export declare function createDocuments(env: RuntimeEnvironment, connection: vscode.Connection): {
29
30
  data: {
30
31
  clear: () => void;
31
32
  values: () => IterableIterator<IncrementalScriptSnapshot>;
@@ -148,17 +148,21 @@ function _combineContinuousChangeRanges(a, b) {
148
148
  const newLength = aDiff + bDiff + length;
149
149
  return { span: { start, length }, newLength };
150
150
  }
151
- function createDocuments(connection) {
152
- const snapshots = (0, uriMap_1.createUriMap)();
151
+ function createDocuments(env, connection) {
152
+ const snapshots = (0, uriMap_1.createUriMap)(env.fileNameToUri);
153
153
  const onDidChangeContents = new Set();
154
154
  const onDidCloses = new Set();
155
155
  connection.onDidOpenTextDocument(params => {
156
+ if (params.textDocument.uri.startsWith('git:/'))
157
+ return;
156
158
  snapshots.uriSet(params.textDocument.uri, new IncrementalScriptSnapshot(params.textDocument.uri, params.textDocument.languageId, params.textDocument.version, params.textDocument.text));
157
159
  for (const cb of onDidChangeContents) {
158
160
  cb({ textDocument: params.textDocument, contentChanges: [{ text: params.textDocument.text }] });
159
161
  }
160
162
  });
161
163
  connection.onDidChangeTextDocument(params => {
164
+ if (params.textDocument.uri.startsWith('git:/'))
165
+ return;
162
166
  const incrementalSnapshot = snapshots.uriGet(params.textDocument.uri);
163
167
  if (incrementalSnapshot) {
164
168
  if (params.contentChanges.every(vscode.TextDocumentContentChangeEvent.isIncremental)) {
@@ -181,6 +185,8 @@ function createDocuments(connection) {
181
185
  }
182
186
  });
183
187
  connection.onDidCloseTextDocument(params => {
188
+ if (params.textDocument.uri.startsWith('git:/'))
189
+ return;
184
190
  snapshots.uriDelete(params.textDocument.uri);
185
191
  for (const cb of onDidCloses) {
186
192
  cb(params);
@@ -1,3 +1,4 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  import type { Workspaces } from '../workspaces';
3
- export declare function register(connection: vscode.Connection, projects: Workspaces): void;
3
+ import { RuntimeEnvironment } from '../../types';
4
+ export declare function register(connection: vscode.Connection, projects: Workspaces, env: RuntimeEnvironment): void;