@volar/typescript 2.4.0-alpha.17 → 2.4.0-alpha.19

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.
@@ -29,6 +29,7 @@ function createProxyLanguageService(languageService) {
29
29
  case 'getDocumentHighlights': return getDocumentHighlights(language, target[p]);
30
30
  case 'getApplicableRefactors': return getApplicableRefactors(language, target[p]);
31
31
  case 'getEditsForRefactor': return getEditsForRefactor(language, target[p]);
32
+ case 'getCombinedCodeFix': return getCombinedCodeFix(language, target[p]);
32
33
  case 'getRenameInfo': return getRenameInfo(language, target[p]);
33
34
  case 'getCodeFixesAtPosition': return getCodeFixesAtPosition(language, target[p]);
34
35
  case 'getEncodedSemanticClassifications': return getEncodedSemanticClassifications(language, target[p]);
@@ -46,6 +47,7 @@ function createProxyLanguageService(languageService) {
46
47
  case 'getCompletionEntryDetails': return getCompletionEntryDetails(language, target[p]);
47
48
  case 'provideInlayHints': return provideInlayHints(language, target[p]);
48
49
  case 'getFileReferences': return getFileReferences(language, target[p]);
50
+ case 'getNavigateToItems': return getNavigateToItems(language, target[p]);
49
51
  }
50
52
  };
51
53
  },
@@ -467,6 +469,13 @@ function getEditsForRefactor(language, getEditsForRefactor) {
467
469
  }
468
470
  };
469
471
  }
472
+ function getCombinedCodeFix(language, getCombinedCodeFix) {
473
+ return (...args) => {
474
+ const codeActions = getCombinedCodeFix(...args);
475
+ codeActions.changes = (0, transform_1.transformFileTextChanges)(language, codeActions.changes, language_core_1.isCodeActionsEnabled);
476
+ return codeActions;
477
+ };
478
+ }
470
479
  function getRenameInfo(language, getRenameInfo) {
471
480
  return (filePath, position, options) => {
472
481
  const fileName = filePath.replace(windowsPathReg, '/');
@@ -861,6 +870,15 @@ function getFileReferences(language, getFileReferences) {
861
870
  return (0, dedupe_1.dedupeDocumentSpans)(resolved);
862
871
  };
863
872
  }
873
+ function getNavigateToItems(language, getNavigateToItems) {
874
+ return (...args) => {
875
+ const unresolved = getNavigateToItems(...args);
876
+ const resolved = unresolved
877
+ .map(s => (0, transform_1.transformDocumentSpan)(language, s, language_core_1.isReferencesEnabled))
878
+ .filter(s => !!s);
879
+ return (0, dedupe_1.dedupeDocumentSpans)(resolved);
880
+ };
881
+ }
864
882
  function linkedCodeFeatureWorker(language, fileName, position, filter, worker, getLinkedCodes) {
865
883
  const results = [];
866
884
  const processedFilePositions = new Set();
@@ -8,3 +8,14 @@ export declare function runTsc(tscPath: string, options: string[] | {
8
8
  extraSupportedExtensions: string[];
9
9
  extraExtensionsToRemove: string[];
10
10
  }, _getLanguagePlugins: typeof getLanguagePlugins): void;
11
+ /**
12
+ * Replaces the code of typescript to add support for additional extensions and language plugins.
13
+ *
14
+ * @param tsc - The original code of typescript.
15
+ * @param proxyApiPath - The path to the proxy API.
16
+ * @param extraSupportedExtensions - An array of additional supported extensions.
17
+ * @param extraExtensionsToRemove - An array of extensions to remove.
18
+ * @param getLanguagePluginsFile - The file to get language plugins from.
19
+ * @returns The modified typescript code.
20
+ */
21
+ export declare function transformTscContent(tsc: string, proxyApiPath: string, extraSupportedExtensions: string[], extraExtensionsToRemove: string[], getLanguagePluginsFile?: string): string;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLanguagePlugins = void 0;
4
4
  exports.runTsc = runTsc;
5
+ exports.transformTscContent = transformTscContent;
5
6
  const fs = require("fs");
6
7
  let getLanguagePlugins = () => [];
7
8
  exports.getLanguagePlugins = getLanguagePlugins;
@@ -22,38 +23,7 @@ function runTsc(tscPath, options, _getLanguagePlugins) {
22
23
  extraSupportedExtensions = options.extraSupportedExtensions;
23
24
  extraExtensionsToRemove = options.extraExtensionsToRemove;
24
25
  }
25
- const needPatchExtenstions = extraSupportedExtensions.filter(ext => !extraExtensionsToRemove.includes(ext));
26
- // Add allow extensions
27
- if (extraSupportedExtensions.length) {
28
- const extsText = extraSupportedExtensions.map(ext => `"${ext}"`).join(', ');
29
- tsc = replace(tsc, /supportedTSExtensions = .*(?=;)/, s => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`);
30
- tsc = replace(tsc, /supportedJSExtensions = .*(?=;)/, s => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`);
31
- tsc = replace(tsc, /allSupportedExtensions = .*(?=;)/, s => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`);
32
- }
33
- // Use to emit basename.xxx to basename.d.ts instead of basename.xxx.d.ts
34
- if (extraExtensionsToRemove.length) {
35
- const extsText = extraExtensionsToRemove.map(ext => `"${ext}"`).join(', ');
36
- tsc = replace(tsc, /extensionsToRemove = .*(?=;)/, s => s + `.concat([${extsText}])`);
37
- }
38
- // Support for basename.xxx to basename.xxx.d.ts
39
- if (needPatchExtenstions.length) {
40
- const extsText = needPatchExtenstions.map(ext => `"${ext}"`).join(', ');
41
- tsc = replace(tsc, /function changeExtension\(/, s => `function changeExtension(path, newExtension) {
42
- return [${extsText}].some(ext => path.endsWith(ext))
43
- ? path + newExtension
44
- : _changeExtension(path, newExtension)
45
- }\n` + s.replace('changeExtension', '_changeExtension'));
46
- }
47
- // proxy createProgram
48
- tsc = replace(tsc, /function createProgram\(.+\) {/, s => `var createProgram = require(${JSON.stringify(proxyApiPath)}).proxyCreateProgram(`
49
- + [
50
- `new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } )`,
51
- `_createProgram`,
52
- `require(${JSON.stringify(__filename)}).getLanguagePlugins`,
53
- ].join(', ')
54
- + `);\n`
55
- + s.replace('createProgram', '_createProgram'));
56
- return tsc;
26
+ return transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove);
57
27
  }
58
28
  return readFileSync(...args);
59
29
  };
@@ -65,6 +35,50 @@ function runTsc(tscPath, options, _getLanguagePlugins) {
65
35
  delete require.cache[tscPath];
66
36
  }
67
37
  }
38
+ /**
39
+ * Replaces the code of typescript to add support for additional extensions and language plugins.
40
+ *
41
+ * @param tsc - The original code of typescript.
42
+ * @param proxyApiPath - The path to the proxy API.
43
+ * @param extraSupportedExtensions - An array of additional supported extensions.
44
+ * @param extraExtensionsToRemove - An array of extensions to remove.
45
+ * @param getLanguagePluginsFile - The file to get language plugins from.
46
+ * @returns The modified typescript code.
47
+ */
48
+ function transformTscContent(tsc, proxyApiPath, extraSupportedExtensions, extraExtensionsToRemove, getLanguagePluginsFile = __filename) {
49
+ const neededPatchExtenstions = extraSupportedExtensions.filter(ext => !extraExtensionsToRemove.includes(ext));
50
+ // Add allow extensions
51
+ if (extraSupportedExtensions.length) {
52
+ const extsText = extraSupportedExtensions.map(ext => `"${ext}"`).join(', ');
53
+ tsc = replace(tsc, /supportedTSExtensions = .*(?=;)/, s => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`);
54
+ tsc = replace(tsc, /supportedJSExtensions = .*(?=;)/, s => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`);
55
+ tsc = replace(tsc, /allSupportedExtensions = .*(?=;)/, s => s + `.map((group, i) => i === 0 ? group.splice(0, 0, ${extsText}) && group : group)`);
56
+ }
57
+ // Use to emit basename.xxx to basename.d.ts instead of basename.xxx.d.ts
58
+ if (extraExtensionsToRemove.length) {
59
+ const extsText = extraExtensionsToRemove.map(ext => `"${ext}"`).join(', ');
60
+ tsc = replace(tsc, /extensionsToRemove = .*(?=;)/, s => s + `.concat([${extsText}])`);
61
+ }
62
+ // Support for basename.xxx to basename.xxx.d.ts
63
+ if (neededPatchExtenstions.length) {
64
+ const extsText = neededPatchExtenstions.map(ext => `"${ext}"`).join(', ');
65
+ tsc = replace(tsc, /function changeExtension\(/, s => `function changeExtension(path, newExtension) {
66
+ return [${extsText}].some(ext => path.endsWith(ext))
67
+ ? path + newExtension
68
+ : _changeExtension(path, newExtension)
69
+ }\n` + s.replace('changeExtension', '_changeExtension'));
70
+ }
71
+ // proxy createProgram
72
+ tsc = replace(tsc, /function createProgram\(.+\) {/, s => `var createProgram = require(${JSON.stringify(proxyApiPath)}).proxyCreateProgram(`
73
+ + [
74
+ `new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } )`,
75
+ `_createProgram`,
76
+ `require(${JSON.stringify(getLanguagePluginsFile)}).getLanguagePlugins`,
77
+ ].join(', ')
78
+ + `);\n`
79
+ + s.replace('createProgram', '_createProgram'));
80
+ return tsc;
81
+ }
68
82
  function replace(text, ...[search, replace]) {
69
83
  const before = text;
70
84
  text = text.replace(search, replace);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "2.4.0-alpha.17",
3
+ "version": "2.4.0-alpha.19",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,14 +12,14 @@
12
12
  "directory": "packages/typescript"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.4.0-alpha.17",
15
+ "@volar/language-core": "2.4.0-alpha.19",
16
16
  "path-browserify": "^1.0.1",
17
17
  "vscode-uri": "^3.0.8"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "latest",
21
21
  "@types/path-browserify": "latest",
22
- "@volar/language-service": "2.4.0-alpha.17"
22
+ "@volar/language-service": "2.4.0-alpha.19"
23
23
  },
24
- "gitHead": "d0c3954d27f67f9867ea1e7c89bbf7f8365cab7a"
24
+ "gitHead": "cbb14a44f72c365c1e8d52eff9580fb4e9765f15"
25
25
  }