@tsrx/language-server 0.4.12 → 0.5.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.
package/dist/language-server.js
CHANGED
|
@@ -1930,14 +1930,15 @@ function create_embedded_code_from_mapping(mapping, languageId) {
|
|
|
1930
1930
|
* Every body is treated as TypeScript (a superset of JS), so the attributes are
|
|
1931
1931
|
* never inspected. The opening-tag pattern refuses to match self-closing
|
|
1932
1932
|
* `<script src=... />` tags (the `/` before `>` must not close the tag), so they
|
|
1933
|
-
* can't swallow a later real script's body.
|
|
1933
|
+
* can't swallow a later real script's body. A body ends where the parser ends
|
|
1934
|
+
* it: at `<\/script`, optional whitespace, then `>`.
|
|
1934
1935
|
* @param {string} code - The source code to extract scripts from
|
|
1935
1936
|
* @returns {VirtualCode[]} Array of embedded TypeScript virtual codes
|
|
1936
1937
|
*/
|
|
1937
1938
|
function extractScriptFromSource(code) {
|
|
1938
1939
|
/** @type {VirtualCode[]} */
|
|
1939
1940
|
const embeddedCodes = [];
|
|
1940
|
-
const scriptRegex = /<script\b((?:[^>"'/]|"[^"]*"|'[^']*'|\/(?!>))*)>([\s\S]*?)<\/script
|
|
1941
|
+
const scriptRegex = /<script\b((?:[^>"'/]|"[^"]*"|'[^']*'|\/(?!>))*)>([\s\S]*?)<\/script[\t\n\f\r ]*>/gi;
|
|
1941
1942
|
let match;
|
|
1942
1943
|
let index = 0;
|
|
1943
1944
|
while ((match = scriptRegex.exec(code)) !== null) {
|
|
@@ -21643,7 +21644,7 @@ var require_node = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
21643
21644
|
//#region src/compileErrorDiagnosticPlugin.js
|
|
21644
21645
|
var import_node = require_node();
|
|
21645
21646
|
/**
|
|
21646
|
-
* @import {Diagnostic, Range, LanguageServicePlugin, LanguageServiceContext, Position, Mapper} from '@volar/language-server';
|
|
21647
|
+
* @import {Diagnostic, Range, LanguageServicePlugin, LanguageServiceContext, Position, Mapper, CancellationToken, CodeInformation} from '@volar/language-server';
|
|
21647
21648
|
* @import {TextDocument} from 'vscode-languageserver-textdocument';
|
|
21648
21649
|
* @import {TSRXVirtualCodeInstance} from '@tsrx/typescript-plugin/src/language.js';
|
|
21649
21650
|
*/
|
|
@@ -21662,15 +21663,25 @@ function createCompileErrorDiagnosticPlugin() {
|
|
|
21662
21663
|
workspaceDiagnostics: false
|
|
21663
21664
|
} },
|
|
21664
21665
|
create(context) {
|
|
21665
|
-
return { provideDiagnostics(document,
|
|
21666
|
+
return { async provideDiagnostics(document, token) {
|
|
21666
21667
|
log$8("Providing TSRX diagnostics for:", document.uri);
|
|
21667
21668
|
/** @type {Diagnostic[]} */
|
|
21668
21669
|
const diagnostics = [];
|
|
21669
21670
|
const { virtualCode, sourceMap } = getVirtualCode(document, context);
|
|
21670
21671
|
if (!virtualCode || virtualCode.languageId !== "tsrx") return diagnostics;
|
|
21671
21672
|
if (!virtualCode.fatalErrors.length && !virtualCode.usageErrors.length) return diagnostics;
|
|
21673
|
+
/** @type {Set<string> | undefined} */
|
|
21674
|
+
let typescript_diagnostics;
|
|
21672
21675
|
for (const error of [...virtualCode.fatalErrors, ...virtualCode.usageErrors]) {
|
|
21673
21676
|
const diagnostic = parseCompilationErrorWithDocument(error, virtualCode, sourceMap, document);
|
|
21677
|
+
if (error.type !== "fatal" && error.code?.startsWith("TS") && sourceMap) {
|
|
21678
|
+
typescript_diagnostics ??= await get_typescript_diagnostics(context, document, sourceMap, token);
|
|
21679
|
+
const place = shown_at(diagnostic, error.code, document, sourceMap);
|
|
21680
|
+
if (place && typescript_diagnostics.has(place)) {
|
|
21681
|
+
log$8("Leaving", error.code, "to TypeScript:", error.message);
|
|
21682
|
+
continue;
|
|
21683
|
+
}
|
|
21684
|
+
}
|
|
21674
21685
|
diagnostics.push(diagnostic);
|
|
21675
21686
|
}
|
|
21676
21687
|
log$8("Generated", diagnostics.length, "diagnostics");
|
|
@@ -21680,6 +21691,57 @@ function createCompileErrorDiagnosticPlugin() {
|
|
|
21680
21691
|
};
|
|
21681
21692
|
}
|
|
21682
21693
|
/**
|
|
21694
|
+
* Where the editor shows each diagnostic TypeScript reports for the virtual
|
|
21695
|
+
* code, as `shown_at` gives it. They come from the `typescript-semantic` plugin,
|
|
21696
|
+
* so they are the ones the editor gets: `createTypeScriptDiagnosticFilterPlugin`
|
|
21697
|
+
* has already left out the suppressed ones, and none come back when TypeScript
|
|
21698
|
+
* validation is off or the plugin is disabled. TypeScript caches a program's
|
|
21699
|
+
* syntactic and semantic diagnostics, so the plugin reuses them when Volar asks
|
|
21700
|
+
* it next.
|
|
21701
|
+
* @param {LanguageServiceContext} context
|
|
21702
|
+
* @param {TextDocument} document
|
|
21703
|
+
* @param {Mapper} sourceMap
|
|
21704
|
+
* @param {CancellationToken} token
|
|
21705
|
+
* @returns {Promise<Set<string>>}
|
|
21706
|
+
*/
|
|
21707
|
+
async function get_typescript_diagnostics(context, document, sourceMap, token) {
|
|
21708
|
+
/** @type {Set<string>} */
|
|
21709
|
+
const places = /* @__PURE__ */ new Set();
|
|
21710
|
+
const diagnostics = await (context.plugins.find(([plugin, instance]) => plugin.name === "typescript-semantic" && !context.disabledServicePlugins.has(instance))?.[1])?.provideDiagnostics?.(document, token) ?? [];
|
|
21711
|
+
for (const diagnostic of diagnostics) {
|
|
21712
|
+
if (typeof diagnostic.code !== "number") continue;
|
|
21713
|
+
const place = shown_at(diagnostic, `TS${diagnostic.code}`, document, sourceMap);
|
|
21714
|
+
if (place) places.add(place);
|
|
21715
|
+
}
|
|
21716
|
+
return places;
|
|
21717
|
+
}
|
|
21718
|
+
/**
|
|
21719
|
+
* The code of `diagnostic` and the source offset the editor shows it at, or
|
|
21720
|
+
* `null` when the editor leaves it out. Volar maps a diagnostic's range back to
|
|
21721
|
+
* the source through the mappings that report diagnostics, and leaves out a
|
|
21722
|
+
* diagnostic whose range doesn't map, such as one that ends in text the
|
|
21723
|
+
* mappings don't cover (`transformDiagnostic` in `@volar/language-service`).
|
|
21724
|
+
* @param {Diagnostic} diagnostic
|
|
21725
|
+
* @param {string} code
|
|
21726
|
+
* @param {TextDocument} document
|
|
21727
|
+
* @param {Mapper} sourceMap
|
|
21728
|
+
* @returns {string | null}
|
|
21729
|
+
*/
|
|
21730
|
+
function shown_at(diagnostic, code, document, sourceMap) {
|
|
21731
|
+
const range = sourceMap.toSourceRange(document.offsetAt(diagnostic.range.start), document.offsetAt(diagnostic.range.end), true, (data) => reports_diagnostic(data, diagnostic)).next().value;
|
|
21732
|
+
return range ? `${code}@${range[0]}` : null;
|
|
21733
|
+
}
|
|
21734
|
+
/**
|
|
21735
|
+
* Whether a mapping reports `diagnostic`, as Volar's `shouldReportDiagnostics`
|
|
21736
|
+
* decides it.
|
|
21737
|
+
* @param {CodeInformation} data
|
|
21738
|
+
* @param {Diagnostic} diagnostic
|
|
21739
|
+
* @returns {boolean}
|
|
21740
|
+
*/
|
|
21741
|
+
function reports_diagnostic(data, diagnostic) {
|
|
21742
|
+
return typeof data.verification === "object" ? data.verification.shouldReport?.(diagnostic.source, diagnostic.code) ?? true : !!data.verification;
|
|
21743
|
+
}
|
|
21744
|
+
/**
|
|
21683
21745
|
* @param {CompileError} error
|
|
21684
21746
|
* @param {TSRXVirtualCodeInstance} virtualCode
|
|
21685
21747
|
* @param {Mapper | undefined} sourceMap
|
|
@@ -23709,4 +23771,4 @@ Object.defineProperty(exports, 'createTsrxLanguageServer', {
|
|
|
23709
23771
|
return createTsrxLanguageServer;
|
|
23710
23772
|
}
|
|
23711
23773
|
});
|
|
23712
|
-
//# sourceMappingURL=server-
|
|
23774
|
+
//# sourceMappingURL=server-C9rY0GfG.js.map
|