@volar/typescript
Advanced tools
Comparing version 2.2.0-alpha.1 to 2.2.0-alpha.2
@@ -1,4 +0,4 @@ | ||
import { type Language } from '@volar/language-core'; | ||
import type { Language } from '@volar/language-core'; | ||
import type * as ts from 'typescript'; | ||
export declare function decorateLanguageServiceHost(language: Language, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript')): void; | ||
export declare function decorateLanguageServiceHost(ts: typeof import('typescript'), language: Language, languageServiceHost: ts.LanguageServiceHost, getLanguageId: (fileName: string) => string): void; | ||
export declare function searchExternalFiles(ts: typeof import('typescript'), project: ts.server.Project, exts: string[]): string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.searchExternalFiles = exports.decorateLanguageServiceHost = void 0; | ||
const language_core_1 = require("@volar/language-core"); | ||
const resolveModuleName_1 = require("../resolveModuleName"); | ||
function decorateLanguageServiceHost(language, languageServiceHost, ts) { | ||
function decorateLanguageServiceHost(ts, language, languageServiceHost, getLanguageId) { | ||
let extraProjectVersion = 0; | ||
@@ -84,3 +83,3 @@ const exts = language.plugins | ||
extraProjectVersion++; | ||
const sourceScript = language.scripts.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot); | ||
const sourceScript = language.scripts.set(fileName, getLanguageId(fileName), snapshot); | ||
if (sourceScript.generated) { | ||
@@ -87,0 +86,0 @@ const text = snapshot.getText(0, snapshot.getLength()); |
import type * as ts from 'typescript'; | ||
import { LanguagePlugin } from '@volar/language-core'; | ||
export declare function proxyCreateProgram(ts: typeof import('typescript'), original: typeof ts['createProgram'], extensions: string[], getLanguagePlugins: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin[]): typeof import("typescript").createProgram; | ||
export declare function proxyCreateProgram(ts: typeof import('typescript'), original: typeof ts['createProgram'], getLanguagePlugins: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin[], getLanguageId: (fileName: string) => string): typeof import("typescript").createProgram; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const language_core_1 = require("@volar/language-core"); | ||
function proxyCreateProgram(ts, original, extensions, getLanguagePlugins) { | ||
function proxyCreateProgram(ts, original, getLanguagePlugins, getLanguageId) { | ||
return new Proxy(original, { | ||
@@ -12,4 +12,8 @@ apply: (target, thisArg, args) => { | ||
assert(!!options.host, '!!options.host'); | ||
const languagePlugins = getLanguagePlugins(ts, options); | ||
const extensions = languagePlugins | ||
.map(plugin => plugin.typescript?.extraFileExtensions.map(({ extension }) => `.${extension}`) ?? []) | ||
.flat(); | ||
const sourceFileToSnapshotMap = new WeakMap(); | ||
const language = (0, language_core_1.createLanguage)(getLanguagePlugins(ts, options), ts.sys.useCaseSensitiveFileNames, fileName => { | ||
const language = (0, language_core_1.createLanguage)(languagePlugins, ts.sys.useCaseSensitiveFileNames, fileName => { | ||
let snapshot; | ||
@@ -36,3 +40,3 @@ assert(originalSourceFiles.has(fileName), `originalSourceFiles.has(${fileName})`); | ||
if (snapshot) { | ||
language.scripts.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot); | ||
language.scripts.set(fileName, getLanguageId(fileName), snapshot); | ||
} | ||
@@ -103,3 +107,3 @@ else { | ||
// TODO: #128 | ||
program.__volar__ = { files: language }; | ||
program.__volar__ = { language }; | ||
return program; | ||
@@ -106,0 +110,0 @@ function resolveModuleName(name, containingFile, options, redirectedReference) { |
@@ -5,2 +5,3 @@ import { Language, CodeInformation, SourceMap, SourceScript } from '@volar/language-core'; | ||
export declare function transformDiagnostic<T extends ts.Diagnostic>(language: Language, diagnostic: T): T | undefined; | ||
export declare function transformSourceFile(sourceFile: ts.SourceFile, sourceText: string): ts.SourceFile; | ||
export declare function transformFileTextChanges(language: Language, changes: ts.FileTextChanges, filter: (data: CodeInformation) => boolean): ts.FileTextChanges | undefined; | ||
@@ -7,0 +8,0 @@ export declare function transformDocumentSpan<T extends ts.DocumentSpan>(language: Language, documentSpan: T, filter: (data: CodeInformation) => boolean, shouldFallback?: boolean): T | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toGeneratedOffset = exports.toSourceOffset = exports.transformTextSpan = exports.transformTextChange = exports.transformSpan = exports.transformDocumentSpan = exports.transformFileTextChanges = exports.transformDiagnostic = exports.transformCallHierarchyItem = void 0; | ||
exports.toGeneratedOffset = exports.toSourceOffset = exports.transformTextSpan = exports.transformTextChange = exports.transformSpan = exports.transformDocumentSpan = exports.transformFileTextChanges = exports.transformSourceFile = exports.transformDiagnostic = exports.transformCallHierarchyItem = void 0; | ||
const language_core_1 = require("@volar/language-core"); | ||
const utils_1 = require("./utils"); | ||
const transformedDiagnostics = new WeakMap(); | ||
const transformedSourceFiles = new WeakMap(); | ||
function transformCallHierarchyItem(language, item, filter) { | ||
@@ -37,2 +38,3 @@ const span = transformSpan(language, item.file, item.span, filter); | ||
length: sourceSpan.length, | ||
file: transformSourceFile(diagnostic.file, sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength())), | ||
}); | ||
@@ -52,2 +54,12 @@ } | ||
exports.transformDiagnostic = transformDiagnostic; | ||
function transformSourceFile(sourceFile, sourceText) { | ||
if (!transformedSourceFiles.has(sourceFile)) { | ||
transformedSourceFiles.set(sourceFile, { | ||
...sourceFile, | ||
text: sourceText, | ||
}); | ||
} | ||
return transformedSourceFiles.get(sourceFile); | ||
} | ||
exports.transformSourceFile = transformSourceFile; | ||
function transformFileTextChanges(language, changes, filter) { | ||
@@ -54,0 +66,0 @@ const [_, source] = (0, utils_1.getServiceScript)(language, changes.fileName); |
import type * as ts from 'typescript'; | ||
import { LanguagePlugin } from '@volar/language-core'; | ||
export declare function createAsyncLanguageServicePlugin(extensions: string[], scriptKind: ts.ScriptKind, loadLanguagePlugins: (ts: typeof import('typescript'), info: ts.server.PluginCreateInfo) => Promise<LanguagePlugin[]>): ts.server.PluginModuleFactory; | ||
export declare function createAsyncLanguageServicePlugin(extensions: string[], scriptKind: ts.ScriptKind, loadLanguagePlugins: (ts: typeof import('typescript'), info: ts.server.PluginCreateInfo) => Promise<LanguagePlugin[]>, getLanguageId: (fileName: string) => string): ts.server.PluginModuleFactory; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const decoratedLanguageServiceHosts = new WeakSet(); | ||
function createAsyncLanguageServicePlugin(extensions, scriptKind, loadLanguagePlugins) { | ||
function createAsyncLanguageServicePlugin(extensions, scriptKind, loadLanguagePlugins, getLanguageId) { | ||
return modules => { | ||
@@ -59,3 +59,3 @@ const { typescript: ts } = modules; | ||
if (snapshot) { | ||
language.scripts.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot); | ||
language.scripts.set(fileName, getLanguageId(fileName), snapshot); | ||
} | ||
@@ -67,3 +67,3 @@ else { | ||
(0, decorateLanguageService_1.decorateLanguageService)(language, info.languageService); | ||
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(language, info.languageServiceHost, ts); | ||
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(ts, language, info.languageServiceHost, getLanguageId); | ||
info.project.markAsDirty(); | ||
@@ -70,0 +70,0 @@ initialized = true; |
import type * as ts from 'typescript'; | ||
import { LanguagePlugin } from '@volar/language-core'; | ||
export declare function createLanguageServicePlugin(loadLanguagePlugins: (ts: typeof import('typescript'), info: ts.server.PluginCreateInfo) => LanguagePlugin[]): ts.server.PluginModuleFactory; | ||
export declare function createLanguageServicePlugin(loadLanguagePlugins: (ts: typeof import('typescript'), info: ts.server.PluginCreateInfo) => LanguagePlugin[], getLanguageId: (fileName: string) => string): ts.server.PluginModuleFactory; | ||
export declare function arrayItemsEqual(a: string[], b: string[]): boolean; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const decoratedLanguageServiceHosts = new WeakSet(); | ||
function createLanguageServicePlugin(loadLanguagePlugins) { | ||
function createLanguageServicePlugin(loadLanguagePlugins, getLanguageId) { | ||
return modules => { | ||
@@ -30,3 +30,3 @@ const { typescript: ts } = modules; | ||
if (snapshot) { | ||
language.scripts.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot); | ||
language.scripts.set(fileName, getLanguageId(fileName), snapshot); | ||
} | ||
@@ -38,3 +38,3 @@ else { | ||
(0, decorateLanguageService_1.decorateLanguageService)(language, info.languageService); | ||
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(language, info.languageServiceHost, ts); | ||
(0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(ts, language, info.languageServiceHost, getLanguageId); | ||
} | ||
@@ -41,0 +41,0 @@ return info.languageService; |
import type * as ts from 'typescript'; | ||
import type { LanguagePlugin } from '@volar/language-core'; | ||
export declare let getLanguagePlugins: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin[]; | ||
export declare function runTsc(tscPath: string, extensions: string[], _getLanguagePlugins: typeof getLanguagePlugins): void; | ||
export declare let getLanguageId: (fileName: string) => string; | ||
export declare function runTsc(tscPath: string, extensions: string[], _getLanguagePlugins: typeof getLanguagePlugins, _getLanguageId: typeof getLanguageId): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runTsc = exports.getLanguagePlugins = void 0; | ||
exports.runTsc = exports.getLanguageId = exports.getLanguagePlugins = void 0; | ||
const fs = require("fs"); | ||
let getLanguagePlugins = () => []; | ||
exports.getLanguagePlugins = getLanguagePlugins; | ||
function runTsc(tscPath, extensions, _getLanguagePlugins) { | ||
let getLanguageId = () => 'ts'; | ||
exports.getLanguageId = getLanguageId; | ||
function runTsc(tscPath, extensions, _getLanguagePlugins, _getLanguageId) { | ||
exports.getLanguagePlugins = _getLanguagePlugins; | ||
exports.getLanguageId = _getLanguageId; | ||
const proxyApiPath = require.resolve('../node/proxyCreateProgram'); | ||
@@ -21,6 +24,8 @@ const readFileSync = fs.readFileSync; | ||
tsc = replace(tsc, /function createProgram\(.+\) {/, s => `var createProgram = require(${JSON.stringify(proxyApiPath)}).proxyCreateProgram(` | ||
+ `new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } ), ` | ||
+ `_createProgram, ` | ||
+ `[${extsText}], ` | ||
+ `require(${JSON.stringify(__filename)}).getLanguagePlugins` | ||
+ [ | ||
`new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } )`, | ||
`_createProgram`, | ||
`require(${JSON.stringify(__filename)}).getLanguagePlugins`, | ||
`require(${JSON.stringify(__filename)}).getLanguageId`, | ||
].join(', ') | ||
+ `);\n` | ||
@@ -27,0 +32,0 @@ + s.replace('createProgram', '_createProgram')); |
{ | ||
"name": "@volar/typescript", | ||
"version": "2.2.0-alpha.1", | ||
"version": "2.2.0-alpha.2", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "2.2.0-alpha.1", | ||
"@volar/language-core": "2.2.0-alpha.2", | ||
"path-browserify": "^1.0.1" | ||
@@ -22,5 +22,5 @@ }, | ||
"@types/path-browserify": "latest", | ||
"@volar/language-service": "2.2.0-alpha.1" | ||
"@volar/language-service": "2.2.0-alpha.2" | ||
}, | ||
"gitHead": "e6dcb83ecadcfcc9e22083eea61e1ee817a9d483" | ||
"gitHead": "c6a538c915cc8b32ad9a7ca1092a29a326d49161" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172433
3698
108
+ Added@volar/language-core@2.2.0-alpha.2(transitive)
+ Added@volar/source-map@2.2.0-alpha.2(transitive)
- Removed@volar/language-core@2.2.0-alpha.1(transitive)
- Removed@volar/source-map@2.2.0-alpha.1(transitive)