@tsrx/language-server 0.7.10 → 0.7.12
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
|
@@ -22966,12 +22966,18 @@ function createCompileErrorDiagnosticPlugin() {
|
|
|
22966
22966
|
log$7("Providing TSRX diagnostics for:", document.uri);
|
|
22967
22967
|
/** @type {Diagnostic[]} */
|
|
22968
22968
|
const diagnostics = [];
|
|
22969
|
-
const { virtualCode, sourceMap } = getVirtualCode(document, context);
|
|
22969
|
+
const { virtualCode, sourceMap, sourceScript } = getVirtualCode(document, context);
|
|
22970
|
+
if (virtualCode?.languageId === "css") {
|
|
22971
|
+
const root = sourceScript?.generated?.root;
|
|
22972
|
+
return root?.languageId === "tsrx" && has_own_id(virtualCode, root) ? css_region_diagnostics(root, virtualCode, document) : [];
|
|
22973
|
+
}
|
|
22970
22974
|
if (!virtualCode || virtualCode.languageId !== "tsrx") return diagnostics;
|
|
22971
22975
|
if (!virtualCode.fatalErrors.length && !virtualCode.usageErrors.length) return diagnostics;
|
|
22972
22976
|
/** @type {Set<string> | undefined} */
|
|
22973
22977
|
let typescript_diagnostics;
|
|
22974
22978
|
for (const error of [...virtualCode.fatalErrors, ...virtualCode.usageErrors]) {
|
|
22979
|
+
const css = error.type === "fatal" ? null : css_region_of(error, virtualCode);
|
|
22980
|
+
if (css && has_own_id(css, virtualCode)) continue;
|
|
22975
22981
|
const diagnostic = parseCompilationErrorWithDocument(error, virtualCode, sourceMap, document);
|
|
22976
22982
|
if (error.type !== "fatal" && error.code?.startsWith("TS") && sourceMap) {
|
|
22977
22983
|
typescript_diagnostics ??= await get_typescript_diagnostics(context, document, sourceMap, token);
|
|
@@ -22990,6 +22996,74 @@ function createCompileErrorDiagnosticPlugin() {
|
|
|
22990
22996
|
};
|
|
22991
22997
|
}
|
|
22992
22998
|
/**
|
|
22999
|
+
* The embedded CSS code (a `<style>` body) that holds all of `error`'s range,
|
|
23000
|
+
* if one does.
|
|
23001
|
+
* @param {CompileError} error
|
|
23002
|
+
* @param {TSRXVirtualCodeInstance} root
|
|
23003
|
+
* @returns {import('@volar/language-server').VirtualCode | null}
|
|
23004
|
+
*/
|
|
23005
|
+
function css_region_of(error, root) {
|
|
23006
|
+
if (error.pos === void 0) return null;
|
|
23007
|
+
const end = get_end_offset_from_error(error, error.pos);
|
|
23008
|
+
for (const code of root.embeddedCodes ?? []) {
|
|
23009
|
+
if (code.languageId !== "css") continue;
|
|
23010
|
+
const region = css_region_range(code);
|
|
23011
|
+
if (region && region[0] <= error.pos && end <= region[1]) return code;
|
|
23012
|
+
}
|
|
23013
|
+
return null;
|
|
23014
|
+
}
|
|
23015
|
+
/**
|
|
23016
|
+
* Whether `code` is the only embedded code of `root` with its id. Volar keeps
|
|
23017
|
+
* one code of an id and gives every document of that id that code, so an error
|
|
23018
|
+
* in a code whose id another shares stays on the TSRX document.
|
|
23019
|
+
* @param {import('@volar/language-server').VirtualCode} code
|
|
23020
|
+
* @param {TSRXVirtualCodeInstance} root
|
|
23021
|
+
* @returns {boolean}
|
|
23022
|
+
*/
|
|
23023
|
+
function has_own_id(code, root) {
|
|
23024
|
+
return (root.embeddedCodes ?? []).filter((other) => other.id === code.id).length === 1;
|
|
23025
|
+
}
|
|
23026
|
+
/**
|
|
23027
|
+
* @param {import('@volar/language-server').VirtualCode} code
|
|
23028
|
+
* @returns {[start: number, end: number] | null}
|
|
23029
|
+
*/
|
|
23030
|
+
function css_region_range(code) {
|
|
23031
|
+
const mapping = code.mappings[0];
|
|
23032
|
+
if (!mapping) return null;
|
|
23033
|
+
const start = mapping.sourceOffsets[0];
|
|
23034
|
+
return [start, start + mapping.lengths[0]];
|
|
23035
|
+
}
|
|
23036
|
+
/**
|
|
23037
|
+
* The usage errors of `root` in the `<style>` body `css` is the embedded code
|
|
23038
|
+
* of, on `document`, the embedded CSS, whose offsets are the body's.
|
|
23039
|
+
* @param {TSRXVirtualCodeInstance} root
|
|
23040
|
+
* @param {import('@volar/language-server').VirtualCode} css
|
|
23041
|
+
* @param {TextDocument} document
|
|
23042
|
+
* @returns {Diagnostic[]}
|
|
23043
|
+
*/
|
|
23044
|
+
function css_region_diagnostics(root, css, document) {
|
|
23045
|
+
const region = css_region_range(css);
|
|
23046
|
+
if (!region) return [];
|
|
23047
|
+
/** @type {Diagnostic[]} */
|
|
23048
|
+
const diagnostics = [];
|
|
23049
|
+
for (const error of root.usageErrors) {
|
|
23050
|
+
if (css_region_of(error, root) !== css) continue;
|
|
23051
|
+
const start = error.pos - region[0];
|
|
23052
|
+
const end = get_end_offset_from_error(error, error.pos) - region[0];
|
|
23053
|
+
diagnostics.push({
|
|
23054
|
+
severity: error.severity === "warning" ? import_language_server.DiagnosticSeverity.Warning : import_language_server.DiagnosticSeverity.Error,
|
|
23055
|
+
range: {
|
|
23056
|
+
start: document.positionAt(start),
|
|
23057
|
+
end: document.positionAt(end)
|
|
23058
|
+
},
|
|
23059
|
+
message: error.message,
|
|
23060
|
+
source: DIAGNOSTIC_SOURCE,
|
|
23061
|
+
code: error.code ?? "tsrx-usage-error"
|
|
23062
|
+
});
|
|
23063
|
+
}
|
|
23064
|
+
return diagnostics;
|
|
23065
|
+
}
|
|
23066
|
+
/**
|
|
22993
23067
|
* Where the editor shows each diagnostic TypeScript reports for the virtual
|
|
22994
23068
|
* code, as `shown_at` gives it. They come from the `typescript-semantic` plugin,
|
|
22995
23069
|
* so they are the ones the editor gets: `createTypeScriptDiagnosticFilterPlugin`
|
|
@@ -26257,4 +26331,4 @@ Object.defineProperty(exports, 'createTsrxLanguageServer', {
|
|
|
26257
26331
|
return createTsrxLanguageServer;
|
|
26258
26332
|
}
|
|
26259
26333
|
});
|
|
26260
|
-
//# sourceMappingURL=server-
|
|
26334
|
+
//# sourceMappingURL=server-9-3sh49Z.js.map
|