fix(adminui): script analysis reuses one compilation, honours cancellation, indexes the catalog (D2)
R04:P2 - every analysis derives from one process-wide bound base compilation via ReplaceSyntaxTree (the scoped service keeps its current compilation); every entry point takes the request token, the endpoints bind RequestAborted and answer 499 on abort, and the Monaco providers abort their fetch when Monaco cancels the request. R04:P3 - the catalog snapshot carries a sorted, de-duplicated string[] (binary-search prefix completion) and an Ordinal path->info dictionary, built once per snapshot. R04:S1 - Diagnose emits an OTSCRIPT_SETVTAG_INERT warning for each ctx.SetVirtualTag call. It is a warning, so editor-accepts == publish-accepts still holds. Refs #745 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -23,6 +23,30 @@
|
||||
|
||||
const KIND_MAP = { Method: 0, Field: 3, Property: 9, Event: 10, Class: 5, Module: 8, Variable: 4, Text: 18 };
|
||||
|
||||
// POSTs to a script-analysis endpoint, honouring Monaco's CancellationToken: when Monaco abandons a request
|
||||
// (the caret moved, the user kept typing) the fetch is aborted, which cancels HttpContext.RequestAborted
|
||||
// server-side so the Roslyn analysis stops instead of running to completion. Resolves to null when the
|
||||
// request was cancelled or failed, so a provider never applies a superseded answer.
|
||||
async function postAnalysis(path, body, token) {
|
||||
if (token && token.isCancellationRequested) return null;
|
||||
const ac = new AbortController();
|
||||
const sub = token && token.onCancellationRequested ? token.onCancellationRequested(function () { ac.abort(); }) : null;
|
||||
try {
|
||||
const resp = await fetch("/api/script-analysis/" + path, {
|
||||
method: "POST", credentials: "same-origin", signal: ac.signal,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
if (!resp.ok) return null;
|
||||
const data = await resp.json();
|
||||
return (token && token.isCancellationRequested) ? null : data;
|
||||
} catch (e) {
|
||||
return null;
|
||||
} finally {
|
||||
if (sub && sub.dispose) sub.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// The owning-equipment id is stamped onto each editor's model at createEditor time so the globally
|
||||
// registered csharp providers (which only receive the model) can thread it into the {{equip}}/<RefName>
|
||||
// completion + diagnostics. Null on the shared ScriptEdit page (equip-ref features inert there).
|
||||
@@ -31,15 +55,12 @@
|
||||
function registerCSharpProviders() {
|
||||
monaco.languages.registerCompletionItemProvider("csharp", {
|
||||
triggerCharacters: [".", "(", "\""],
|
||||
provideCompletionItems: async function (model, position) {
|
||||
provideCompletionItems: async function (model, position, context, token) {
|
||||
try {
|
||||
const resp = await fetch("/api/script-analysis/completions", {
|
||||
method: "POST", credentials: "same-origin",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ codeText: model.getValue(), line: position.lineNumber, column: position.column, equipmentId: equipmentIdOf(model) })
|
||||
});
|
||||
if (!resp.ok) return { suggestions: [] };
|
||||
const data = await resp.json();
|
||||
const data = await postAnalysis("completions",
|
||||
{ codeText: model.getValue(), line: position.lineNumber, column: position.column, equipmentId: equipmentIdOf(model) },
|
||||
token);
|
||||
if (!data) return { suggestions: [] };
|
||||
const word = model.getWordUntilPosition(position);
|
||||
const wordRange = {
|
||||
startLineNumber: position.lineNumber, endLineNumber: position.lineNumber,
|
||||
@@ -72,31 +93,21 @@
|
||||
}
|
||||
});
|
||||
monaco.languages.registerHoverProvider("csharp", {
|
||||
provideHover: async function (model, position) {
|
||||
provideHover: async function (model, position, token) {
|
||||
try {
|
||||
const resp = await fetch("/api/script-analysis/hover", {
|
||||
method: "POST", credentials: "same-origin",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ codeText: model.getValue(), line: position.lineNumber, column: position.column, equipmentId: equipmentIdOf(model) })
|
||||
});
|
||||
if (!resp.ok) return null;
|
||||
const data = await resp.json();
|
||||
if (!data.markdown) return null;
|
||||
const data = await postAnalysis("hover",
|
||||
{ codeText: model.getValue(), line: position.lineNumber, column: position.column, equipmentId: equipmentIdOf(model) },
|
||||
token);
|
||||
if (!data || !data.markdown) return null;
|
||||
return { contents: [{ value: data.markdown }] };
|
||||
} catch (e) { return null; }
|
||||
}
|
||||
});
|
||||
monaco.languages.registerDocumentFormattingEditProvider("csharp", {
|
||||
provideDocumentFormattingEdits: async function (model) {
|
||||
provideDocumentFormattingEdits: async function (model, options, token) {
|
||||
try {
|
||||
const resp = await fetch("/api/script-analysis/format", {
|
||||
method: "POST", credentials: "same-origin",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ code: model.getValue() })
|
||||
});
|
||||
if (!resp.ok) return [];
|
||||
const data = await resp.json();
|
||||
if (typeof data.code !== "string" || data.code === model.getValue()) return [];
|
||||
const data = await postAnalysis("format", { code: model.getValue() }, token);
|
||||
if (!data || typeof data.code !== "string" || data.code === model.getValue()) return [];
|
||||
return [{ range: model.getFullModelRange(), text: data.code }];
|
||||
} catch (e) { return []; }
|
||||
}
|
||||
@@ -123,16 +134,12 @@
|
||||
monaco.languages.registerSignatureHelpProvider("csharp", {
|
||||
signatureHelpTriggerCharacters: ["(", ","],
|
||||
signatureHelpRetriggerCharacters: [","],
|
||||
provideSignatureHelp: async function (model, position) {
|
||||
provideSignatureHelp: async function (model, position, token) {
|
||||
try {
|
||||
const resp = await fetch("/api/script-analysis/signature-help", {
|
||||
method: "POST", credentials: "same-origin",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ codeText: model.getValue(), line: position.lineNumber, column: position.column })
|
||||
});
|
||||
if (!resp.ok) return null;
|
||||
const data = await resp.json();
|
||||
if (!data.label) return null;
|
||||
const data = await postAnalysis("signature-help",
|
||||
{ codeText: model.getValue(), line: position.lineNumber, column: position.column },
|
||||
token);
|
||||
if (!data || !data.label) return null;
|
||||
return {
|
||||
value: {
|
||||
signatures: [{
|
||||
|
||||
Reference in New Issue
Block a user