@mirascript/monaco 0.1.90 → 0.1.91
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/lsp/index.d.ts.map +1 -1
- package/dist/lsp/index.js +147 -115
- package/dist/lsp/index.js.map +2 -2
- package/dist/lsp/providers/formatter-provider.d.ts +7 -11
- package/dist/lsp/providers/formatter-provider.d.ts.map +1 -1
- package/dist/lsp/worker-core.d.ts +68 -13
- package/dist/lsp/worker-core.d.ts.map +1 -1
- package/dist/lsp/worker-helper.d.ts +10 -0
- package/dist/lsp/worker-helper.d.ts.map +1 -1
- package/dist/lsp/worker.js +20 -11
- package/dist/lsp/worker.js.map +1 -1
- package/dist/{worker-core-MG2FDDNN.js → worker-core-IBUPKM67.js} +15 -20
- package/dist/worker-core-IBUPKM67.js.map +6 -0
- package/package.json +6 -6
- package/src/lsp/index.ts +1 -2
- package/src/lsp/providers/formatter-provider.ts +59 -53
- package/src/lsp/worker-core.ts +86 -34
- package/src/lsp/worker-helper.ts +132 -85
- package/src/lsp/worker.ts +22 -13
- package/dist/worker-core-MG2FDDNN.js.map +0 -6
package/dist/lsp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lsp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CA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AA8B,EAAE,MAAM,yCAAyC,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,OAAO,EACH,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,8BAA8B,EAC9B,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,QAAQ,GACX,CAAC;AAEF,YAAY;AACZ,MAAM,MAAM,WAAW,GAAG;IACtB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,EAAE,sBAAsB,CAAC;IACvC,mBAAmB,EAAE,2BAA2B,CAAC;IACjD,iBAAiB,EAAE,yBAAyB,CAAC;IAC7C,cAAc,EAAE,sBAAsB,CAAC;IACvC,SAAS,EAAE,iBAAiB,CAAC;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,sBAAsB,EAAE,8BAA8B,CAAC;IACvD,aAAa,EAAE,qBAAqB,CAAC;CACxC,CAAC;AAEF,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;KAAG,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS;CAAE,CAAC;AAEnF,sBAAsB;AACtB,wBAAsB,WAAW,CAC7B,eAAe,EAAE,iBAAiB,GAAG,SAAS,EAC9C,QAAQ,GAAE,iBAAsB,GACjC,OAAO,CAAC,WAAW,EAAE,CAAC,CAyDxB"}
|
package/dist/lsp/index.js
CHANGED
|
@@ -989,118 +989,139 @@ async function makeModelMarkers(model, result) {
|
|
|
989
989
|
|
|
990
990
|
// src/lsp/worker-helper.ts
|
|
991
991
|
var cache = /* @__PURE__ */ new Map();
|
|
992
|
-
var worker
|
|
992
|
+
var worker;
|
|
993
|
+
var requestSequence = 0;
|
|
993
994
|
var CACHE_MAX_AGE = 3e4;
|
|
994
995
|
setInterval(() => {
|
|
995
996
|
const now = Date.now();
|
|
996
997
|
for (const [key, { lastAccess }] of cache) {
|
|
997
|
-
if (now - lastAccess > CACHE_MAX_AGE)
|
|
998
|
-
cache.delete(key);
|
|
999
|
-
}
|
|
998
|
+
if (now - lastAccess > CACHE_MAX_AGE) cache.delete(key);
|
|
1000
999
|
}
|
|
1001
1000
|
}, CACHE_MAX_AGE);
|
|
1002
|
-
|
|
1001
|
+
function nextRequestId() {
|
|
1002
|
+
requestSequence = (requestSequence + 1) % Number.MAX_SAFE_INTEGER;
|
|
1003
|
+
return requestSequence;
|
|
1004
|
+
}
|
|
1005
|
+
function modeOf(model) {
|
|
1006
|
+
return model.getLanguageId() === "mirascript-template" ? "Template" : "Script";
|
|
1007
|
+
}
|
|
1008
|
+
async function getWorker() {
|
|
1003
1009
|
if (!worker) {
|
|
1004
|
-
const
|
|
1010
|
+
const instance = new Worker(new URL("#lsp/worker", import.meta.url), {
|
|
1005
1011
|
type: "module",
|
|
1006
1012
|
name: "@mirascript/lsp-server"
|
|
1007
1013
|
});
|
|
1008
1014
|
worker = new Promise((resolve, reject) => {
|
|
1009
|
-
const
|
|
1015
|
+
const timeout = setTimeout(() => {
|
|
1010
1016
|
cleanUp();
|
|
1011
|
-
reject(new Error(
|
|
1017
|
+
reject(new Error("Worker did not respond in time"));
|
|
1018
|
+
}, 3e4);
|
|
1019
|
+
const cleanUp = () => {
|
|
1020
|
+
clearTimeout(timeout);
|
|
1021
|
+
instance.removeEventListener("error", onError);
|
|
1022
|
+
instance.removeEventListener("message", onMessage);
|
|
1012
1023
|
};
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
resolve(w);
|
|
1017
|
-
} else if (e.data instanceof Error) {
|
|
1018
|
-
cleanUp();
|
|
1019
|
-
reject(e.data);
|
|
1020
|
-
}
|
|
1024
|
+
const onError = (event) => {
|
|
1025
|
+
cleanUp();
|
|
1026
|
+
reject(new Error(`Worker failed to start: ${event.message}`));
|
|
1021
1027
|
};
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
w.removeEventListener("message", onMessage);
|
|
1028
|
+
const onMessage = (event) => {
|
|
1029
|
+
if (event.data !== "mirascript lsp ready") return;
|
|
1030
|
+
cleanUp();
|
|
1031
|
+
resolve(instance);
|
|
1027
1032
|
};
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
}, 3e4);
|
|
1033
|
+
instance.addEventListener("error", onError);
|
|
1034
|
+
instance.addEventListener("message", onMessage);
|
|
1031
1035
|
});
|
|
1032
1036
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
const instance = await worker;
|
|
1041
|
-
instance.postMessage(req);
|
|
1042
|
-
const [key, version, source] = req;
|
|
1043
|
-
const [_key, _version, result] = await new Promise((resolve, reject) => {
|
|
1044
|
-
const onMessage = (e) => {
|
|
1045
|
-
if (!(e.data[0] === key && e.data[1] === version)) {
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1037
|
+
return worker;
|
|
1038
|
+
}
|
|
1039
|
+
async function requestWorker(request) {
|
|
1040
|
+
const instance = await getWorker();
|
|
1041
|
+
return new Promise((resolve) => {
|
|
1042
|
+
const onMessage = (event) => {
|
|
1043
|
+
if (event.data?.id !== request.id) return;
|
|
1048
1044
|
instance.removeEventListener("message", onMessage);
|
|
1049
|
-
|
|
1050
|
-
reject(e.data[2]);
|
|
1051
|
-
} else {
|
|
1052
|
-
resolve(e.data);
|
|
1053
|
-
}
|
|
1045
|
+
resolve(event.data);
|
|
1054
1046
|
};
|
|
1055
1047
|
instance.addEventListener("message", onMessage);
|
|
1048
|
+
instance.postMessage(request);
|
|
1056
1049
|
});
|
|
1057
|
-
return new CompileResult(key, version, source, result);
|
|
1058
1050
|
}
|
|
1059
1051
|
var compileImpl;
|
|
1060
|
-
async function compileSync(
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1052
|
+
async function compileSync(request) {
|
|
1053
|
+
compileImpl ??= (await import("../worker-core-IBUPKM67.js")).compile;
|
|
1054
|
+
const result = compileImpl(request.script, request.mode);
|
|
1055
|
+
return new CompileResult(request.key, request.version, request.script, result);
|
|
1056
|
+
}
|
|
1057
|
+
async function compileWorker(request) {
|
|
1058
|
+
try {
|
|
1059
|
+
const response = await requestWorker(request);
|
|
1060
|
+
if (!response.ok) throw new Error(response.error);
|
|
1061
|
+
if (response.kind !== "compile") throw new Error("Unexpected formatter response to compile request");
|
|
1062
|
+
return new CompileResult(request.key, request.version, request.script, response.result);
|
|
1063
|
+
} catch (error) {
|
|
1064
|
+
console.error("Failed to use MiraScript worker, falling back to the current thread:", error);
|
|
1065
|
+
USE_WORKER = false;
|
|
1066
|
+
worker = void 0;
|
|
1067
|
+
return compileSync(request);
|
|
1068
|
+
}
|
|
1068
1069
|
}
|
|
1069
1070
|
var USE_WORKER = typeof Worker === "function";
|
|
1070
1071
|
async function compile(model) {
|
|
1071
1072
|
const version = model.getVersionId();
|
|
1072
|
-
const mode = model
|
|
1073
|
-
const
|
|
1074
|
-
const cached = cache.get(
|
|
1073
|
+
const mode = modeOf(model);
|
|
1074
|
+
const key = model.id;
|
|
1075
|
+
const cached = cache.get(key);
|
|
1075
1076
|
if (cached?.version === version && cached.mode === mode) {
|
|
1076
1077
|
cached.lastAccess = Date.now();
|
|
1077
1078
|
return cached.result;
|
|
1078
1079
|
}
|
|
1079
|
-
const
|
|
1080
|
-
const
|
|
1081
|
-
const
|
|
1082
|
-
void
|
|
1080
|
+
const script = model.getValue();
|
|
1081
|
+
const request = { kind: "compile", id: nextRequestId(), key, version, script, mode };
|
|
1082
|
+
const result = USE_WORKER ? compileWorker(request) : compileSync(request);
|
|
1083
|
+
void result.then(async (compiled) => {
|
|
1083
1084
|
if (model.isDisposed()) return;
|
|
1084
1085
|
const setModelMarkers = editor?.setModelMarkers;
|
|
1085
|
-
if (typeof setModelMarkers
|
|
1086
|
-
const markers = await makeModelMarkers(model,
|
|
1087
|
-
if (
|
|
1088
|
-
setModelMarkers(model, "mirascript", markers);
|
|
1086
|
+
if (typeof setModelMarkers !== "function") return;
|
|
1087
|
+
const markers = await makeModelMarkers(model, compiled);
|
|
1088
|
+
if (markers) setModelMarkers(model, "mirascript", markers);
|
|
1089
1089
|
});
|
|
1090
|
-
const item = {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
result: res
|
|
1095
|
-
};
|
|
1096
|
-
cache.set(cacheKey, item);
|
|
1097
|
-
res.catch(() => {
|
|
1098
|
-
const current = cache.get(cacheKey);
|
|
1099
|
-
if (current === item) {
|
|
1100
|
-
cache.delete(cacheKey);
|
|
1101
|
-
}
|
|
1090
|
+
const item = { version, lastAccess: Date.now(), mode, result };
|
|
1091
|
+
cache.set(key, item);
|
|
1092
|
+
result.catch(() => {
|
|
1093
|
+
if (cache.get(key) === item) cache.delete(key);
|
|
1102
1094
|
});
|
|
1103
|
-
return
|
|
1095
|
+
return result;
|
|
1096
|
+
}
|
|
1097
|
+
var formatImpl;
|
|
1098
|
+
async function formatModel(model, ranges, options) {
|
|
1099
|
+
const request = {
|
|
1100
|
+
kind: "format",
|
|
1101
|
+
id: nextRequestId(),
|
|
1102
|
+
key: model.id,
|
|
1103
|
+
version: model.getVersionId(),
|
|
1104
|
+
script: model.getValue(),
|
|
1105
|
+
mode: modeOf(model),
|
|
1106
|
+
ranges,
|
|
1107
|
+
options
|
|
1108
|
+
};
|
|
1109
|
+
if (!USE_WORKER) {
|
|
1110
|
+
formatImpl ??= (await import("../worker-core-IBUPKM67.js")).formatSource;
|
|
1111
|
+
return formatImpl(request.script, request.mode, request.options, request.ranges);
|
|
1112
|
+
}
|
|
1113
|
+
try {
|
|
1114
|
+
const response = await requestWorker(request);
|
|
1115
|
+
if (!response.ok) throw new Error(response.error);
|
|
1116
|
+
if (response.kind !== "format") throw new Error("Unexpected compile response to format request");
|
|
1117
|
+
return response.result;
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
console.error("Failed to use MiraScript worker, formatting on the current thread:", error);
|
|
1120
|
+
USE_WORKER = false;
|
|
1121
|
+
worker = void 0;
|
|
1122
|
+
formatImpl ??= (await import("../worker-core-IBUPKM67.js")).formatSource;
|
|
1123
|
+
return formatImpl(request.script, request.mode, request.options, request.ranges);
|
|
1124
|
+
}
|
|
1104
1125
|
}
|
|
1105
1126
|
|
|
1106
1127
|
// src/lsp/providers/base.ts
|
|
@@ -2234,49 +2255,61 @@ var DocumentSymbolProvider = class extends Provider {
|
|
|
2234
2255
|
};
|
|
2235
2256
|
|
|
2236
2257
|
// src/lsp/providers/formatter-provider.ts
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
if (
|
|
2241
|
-
return [
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2258
|
+
import { parseDiagnostics as parseDiagnostics2 } from "@mirascript/mirascript/subtle";
|
|
2259
|
+
var DEFAULT_PRINT_WIDTH = 80;
|
|
2260
|
+
async function format(model, ranges, options, token) {
|
|
2261
|
+
if (model.uri.scheme === "mirascript" || token?.isCancellationRequested) return [];
|
|
2262
|
+
if (ranges?.length === 0) return [];
|
|
2263
|
+
const version = model.getVersionId();
|
|
2264
|
+
const offsetRanges = ranges?.map((range) => ({
|
|
2265
|
+
start: model.getOffsetAt(Range.getStartPosition(range)),
|
|
2266
|
+
end: model.getOffsetAt(Range.getEndPosition(range))
|
|
2267
|
+
}));
|
|
2268
|
+
try {
|
|
2269
|
+
const result = await formatModel(model, offsetRanges, {
|
|
2270
|
+
tabSize: options?.tabSize ?? 2,
|
|
2271
|
+
insertSpaces: options?.insertSpaces ?? true,
|
|
2272
|
+
printWidth: DEFAULT_PRINT_WIDTH
|
|
2273
|
+
});
|
|
2274
|
+
if (model.isDisposed() || token?.isCancellationRequested || model.getVersionId() !== version) return [];
|
|
2275
|
+
if (ranges == null && parseDiagnostics2(model.getValue(), result.diagnostics).errors.length > 0) return null;
|
|
2276
|
+
return result.edits.map((edit) => ({
|
|
2277
|
+
range: Range.fromPositions(model.getPositionAt(edit.start), model.getPositionAt(edit.end)),
|
|
2278
|
+
text: edit.text
|
|
2279
|
+
}));
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
console.error("MiraScript formatting failed:", error);
|
|
2282
|
+
return null;
|
|
2283
|
+
}
|
|
2247
2284
|
}
|
|
2248
2285
|
var FormatterProvider = class extends Provider {
|
|
2249
|
-
|
|
2250
|
-
super(...arguments);
|
|
2251
|
-
/** @inheritdoc */
|
|
2252
|
-
this.autoFormatTriggerCharacters = [";", "}", "]", ")"];
|
|
2253
|
-
}
|
|
2254
|
-
/** 进行完整格式化 */
|
|
2286
|
+
/** 返回完整格式化文本;源码已规范时返回原文本。 */
|
|
2255
2287
|
static async format(model, options) {
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2288
|
+
const edits = await format(model, void 0, options, void 0);
|
|
2289
|
+
if (edits == null) return null;
|
|
2290
|
+
if (edits.length === 0) return model.getValue();
|
|
2291
|
+
let output = model.getValue();
|
|
2292
|
+
const offsetEdits = edits.map((edit) => ({
|
|
2293
|
+
start: model.getOffsetAt(Range.getStartPosition(edit.range)),
|
|
2294
|
+
end: model.getOffsetAt(Range.getEndPosition(edit.range)),
|
|
2295
|
+
text: edit.text
|
|
2296
|
+
})).toSorted((left, right) => right.start - left.start);
|
|
2297
|
+
for (const edit of offsetEdits) {
|
|
2298
|
+
output = output.slice(0, edit.start) + edit.text + output.slice(edit.end);
|
|
2299
|
+
}
|
|
2300
|
+
return output;
|
|
2301
|
+
}
|
|
2302
|
+
/** 提供整篇文档格式化编辑。 */
|
|
2260
2303
|
provideDocumentFormattingEdits(model, options, token) {
|
|
2261
|
-
return format(model,
|
|
2304
|
+
return format(model, void 0, options, token).then((edits) => edits ?? []);
|
|
2262
2305
|
}
|
|
2263
|
-
/**
|
|
2306
|
+
/** 提供单个选区格式化编辑。 */
|
|
2264
2307
|
provideDocumentRangeFormattingEdits(model, range, options, token) {
|
|
2265
|
-
return format(model, [range], options,
|
|
2308
|
+
return format(model, [range], options, token).then((edits) => edits ?? []);
|
|
2266
2309
|
}
|
|
2267
|
-
/**
|
|
2310
|
+
/** 提供多个选区格式化编辑。 */
|
|
2268
2311
|
provideDocumentRangesFormattingEdits(model, ranges, options, token) {
|
|
2269
|
-
return format(model, ranges, options,
|
|
2270
|
-
}
|
|
2271
|
-
/** @inheritdoc */
|
|
2272
|
-
provideOnTypeFormattingEdits(model, position, ch, options, token) {
|
|
2273
|
-
return format(
|
|
2274
|
-
model,
|
|
2275
|
-
[Range.fromPositions(position, position)],
|
|
2276
|
-
options,
|
|
2277
|
-
ch === ";" ? "statement" : "expression",
|
|
2278
|
-
token
|
|
2279
|
-
);
|
|
2312
|
+
return format(model, ranges, options, token).then((edits) => edits ?? []);
|
|
2280
2313
|
}
|
|
2281
2314
|
};
|
|
2282
2315
|
|
|
@@ -3052,9 +3085,8 @@ async function registerLSP(contextProvider2, features = {}) {
|
|
|
3052
3085
|
registerIfEnabled("documentSymbol", DocumentSymbolProvider, languages.registerDocumentSymbolProvider);
|
|
3053
3086
|
registerIfEnabled("formatter", FormatterProvider, (language, provider) => {
|
|
3054
3087
|
return [
|
|
3055
|
-
languages.registerDocumentFormattingEditProvider(language, provider)
|
|
3056
|
-
|
|
3057
|
-
// languages.registerOnTypeFormattingEditProvider(language, provider),
|
|
3088
|
+
languages.registerDocumentFormattingEditProvider(language, provider),
|
|
3089
|
+
languages.registerDocumentRangeFormattingEditProvider(language, provider)
|
|
3058
3090
|
];
|
|
3059
3091
|
});
|
|
3060
3092
|
registerIfEnabled("hover", HoverProvider, languages.registerHoverProvider);
|