[Bug] `JSONDocument.getNodeFromOffset` is not a function at runtime
TimonVS opened this issue · comments
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `{
}`;
// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
value,
language: "json",
automaticLayout: true,
});
// Register dynamic completions based on AST
monaco.languages.registerCompletionItemProvider('json', {
provideCompletionItems: async (model, position, context) => {
console.log(monaco.languages.json);
const jsonWorker = await (
await monaco.languages.json.getWorker()
)(model.uri);
const jsonDocument = await jsonWorker.parseJSONDocument(
model.uri.toString()
);
console.log(jsonDocument);
// This works just fine in Monaco Editor Playground
const node = jsonDocument?.getNodeFromOffset(model.getOffsetAt(position));
console.log(node);
const word = model.getWordUntilPosition(position);
return {
suggestions: [
{
kind: monaco.languages.CompletionItemKind.Text,
insertText: '"foo"',
label: 'Foo',
range: {
startLineNumber: position.lineNumber,
endLineNumber: position.lineNumber,
startColumn: word.startColumn,
endColumn: word.endColumn,
},
},
],
};
},
});
Reproduction Steps
I'm trying to create dynamic completions based on the JSON AST. For that I'm utilizing the functionality exposed with this PR: #4299, specifically JSONDocument.getNodeFromOffset
. TypeScript tells me the method is there, but I'm getting a runtime error: Uncaught Error: jsonDocument?.getNodeFromOffset is not a function
.
Reproduction environment with Vite: https://stackblitz.com/edit/vitejs-vite-bhgqgc?file=src%2Fmain.ts
Actual (Problematic) Behavior
Runtime error: Uncaught Error: jsonDocument?.getNodeFromOffset is not a function
Expected Behavior
jsonDocument?.getNodeFromOffset
should work as it does in the Monaco Editor Playground.
Additional Context
No response