feat(editor): enable file-backed Monaco models and add Problems panel; lazy-init project TypeScript IntelliSense

This commit is contained in:
2025-12-30 16:55:00 +00:00
parent ed18360748
commit d177b5a935
8 changed files with 407 additions and 19 deletions

View File

@@ -40,6 +40,11 @@ export class DeesEditorMonaco extends DeesElement {
})
accessor language = 'typescript';
@property({
type: String
})
accessor filePath: string = '';
@property({
type: Object
})
@@ -114,14 +119,35 @@ export class DeesEditorMonaco extends DeesElement {
const isBright = domtoolsInstance.themeManager.goBrightBoolean;
const initialTheme = isBright ? 'vs' : 'vs-dark';
const editor = ((window as any).monaco.editor as typeof monaco.editor).create(container, {
value: this.content,
language: this.language,
const monacoInstance = (window as any).monaco as typeof monaco;
// Create or get model with proper file URI for TypeScript IntelliSense
let model: monaco.editor.ITextModel | null = null;
if (this.filePath) {
const uri = monacoInstance.Uri.parse(`file://${this.filePath}`);
model = monacoInstance.editor.getModel(uri);
if (!model) {
model = monacoInstance.editor.createModel(this.content, this.language, uri);
} else {
model.setValue(this.content);
}
}
const editor = (monacoInstance.editor as typeof monaco.editor).create(container, {
model: model || undefined,
value: model ? undefined : this.content,
language: model ? undefined : this.language,
theme: initialTheme,
useShadowDOM: true,
fontSize: 16,
automaticLayout: true,
wordWrap: this.wordWrap
wordWrap: this.wordWrap,
hover: {
enabled: true,
delay: 300,
sticky: true,
above: false,
},
});
// Subscribe to theme changes
@@ -160,7 +186,35 @@ export class DeesEditorMonaco extends DeesElement {
public async updated(changedProperties: Map<string, any>): Promise<void> {
super.updated(changedProperties);
// Handle content changes
const monacoInstance = (window as any).monaco as typeof monaco;
if (!monacoInstance) return;
// Handle filePath changes - switch to different model
if (changedProperties.has('filePath') && this.filePath) {
const editor = await this.editorDeferred.promise;
const uri = monacoInstance.Uri.parse(`file://${this.filePath}`);
let model = monacoInstance.editor.getModel(uri);
if (!model) {
model = monacoInstance.editor.createModel(this.content, this.language, uri);
} else {
// Update model content if different
if (model.getValue() !== this.content) {
this.isUpdatingFromExternal = true;
model.setValue(this.content);
this.isUpdatingFromExternal = false;
}
}
// Switch editor to use this model
const currentModel = editor.getModel();
if (currentModel?.uri.toString() !== uri.toString()) {
editor.setModel(model);
}
return; // filePath change handles content too
}
// Handle content changes (when no filePath or filePath unchanged)
if (changedProperties.has('content')) {
const editor = await this.editorDeferred.promise;
const currentValue = editor.getValue();
@@ -176,10 +230,7 @@ export class DeesEditorMonaco extends DeesElement {
const editor = await this.editorDeferred.promise;
const model = editor.getModel();
if (model) {
const monacoInstance = (window as any).monaco;
if (monacoInstance) {
monacoInstance.editor.setModelLanguage(model, this.language);
}
monacoInstance.editor.setModelLanguage(model, this.language);
}
}
}