Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export type {
HoverV2,
GetCompletionsParams,
GetHoverParams,
GetDiagnosticsParams,
HighlightToken,
LanguageServiceOptions
LanguageServiceOptions,
ArityInfo
} from './src/language-service/index.js';

export { createLanguageService, Expression, Parser };
25 changes: 25 additions & 0 deletions samples/language-service-sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,30 @@ require(['vs/editor/editor.main'], function () {
highlightDecorations = expressionEditor.deltaDecorations(highlightDecorations, decorations);
}

// Diagnostics - show function argument count errors
function applyDiagnostics() {
const doc = makeTextDocument(expressionModel);
const diagnostics = ls.getDiagnostics({ textDocument: doc });

// Convert LSP diagnostics to Monaco markers
const markers = diagnostics.map(d => {
const startPos = fromLspPosition(d.range.start);
const endPos = fromLspPosition(d.range.end);
return {
severity: monaco.MarkerSeverity.Error,
message: d.message,
startLineNumber: startPos.lineNumber,
startColumn: startPos.column,
endLineNumber: endPos.lineNumber,
endColumn: endPos.column,
source: d.source || 'expr-eval'
};
});

// Set markers on the model
monaco.editor.setModelMarkers(expressionModel, 'expr-eval', markers);
}

// Syntax highlight JSON
function syntaxHighlightJson(json) {
if (typeof json !== 'string') {
Expand Down Expand Up @@ -599,6 +623,7 @@ require(['vs/editor/editor.main'], function () {
// Event listeners for changes
expressionModel.onDidChangeContent(() => {
applyHighlighting();
applyDiagnostics();
evaluate();
});

Expand Down
10 changes: 10 additions & 0 deletions samples/language-service-sample/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,15 @@ const exampleCases = [
{"rowId": 3, "state": "unchanged", "data": { "InventoryId": 9362, "Description": "Wood", "Weight": { "Unit": "kg", "Amount": 18 } }}
]
}
},
{
id: 'diagnostics-demo',
title: 'Diagnostics Demo',
description: 'Shows error highlighting for incorrect function arguments',
expression: '// Try functions with wrong argument counts:\n// pow() needs 2 args, random() needs 0-1 args\npow(2) + random(1, 2, 3)',
context: {
x: 5,
y: 10
}
}
];
Loading
Loading