Skip to content

Commit

Permalink
test tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Feb 12, 2020
1 parent 4ed989d commit a8da83d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/monaco/src/browser/monaco-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export class MonacoEditorModel implements ITextEditorModel, TextEditorDocument {
this.toDispose.push(this.onDirtyChangedEmitter);
this.toDispose.push(this.onDidChangeValidEmitter);
this.defaultEncoding = options && options.encoding ? options.encoding : undefined;
this.resolveModel = this.readContents().then(content => this.initialize(content || ''));
this.resolveModel = this.readContents().then(
content => this.initialize(content || ''),
e => console.error(`Failed to initialize for '${this.uri}':`, e)
);
}

dispose(): void {
Expand Down Expand Up @@ -266,13 +269,10 @@ export class MonacoEditorModel implements ITextEditorModel, TextEditorDocument {
return;
}

let newText = await this.readContents();
if (token.isCancellationRequested || this._dirty) {
const newText = await this.readContents();
if (newText === undefined || token.isCancellationRequested || this._dirty) {
return;
}
if (newText === undefined) {
newText = '';
}

const value = this.model.getValue();
if (value === newText) {
Expand Down
4 changes: 4 additions & 0 deletions packages/monaco/src/browser/monaco-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ export class MonacoWorkspace implements lang.Workspace {
};
}

/**
* Applies given edits to the given model.
* The model is saved if no editors is opened for it.
*/
applyBackgroundEdit(model: MonacoEditorModel, editOperations: monaco.editor.IIdentifiedSingleEditOperation[]): Promise<void> {
return this.suppressOpenIfDirty(model, async () => {
const editor = MonacoEditor.findByDocument(this.editorManager, model)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
this.readPreferences();
this.toDispose.push(this.model.onDidChangeContent(() => this.readPreferences()));
this.toDispose.push(this.model.onDirtyChanged(() => this.readPreferences()));
this.toDispose.push(this.model.onDidChangeValid(() => this.readPreferences()));

this.toDispose.push(Disposable.create(() => this.reset()));
}
Expand Down Expand Up @@ -165,13 +166,21 @@ export abstract class AbstractResourcePreferenceProvider extends PreferenceProvi
}

protected readPreferences(): void {
if (!this.model || this.model.dirty) {
const model = this.model;
if (!model || model.dirty) {
return;
}
try {
const content = this.model.getText();
const preference = this.getParsedContent(content);
this.handlePreferenceChanges(preference);
let preferences;
if (model.valid) {
const content = model.getText();
preferences = this.getParsedContent(content);
console.log('parsed - ' + this.getUri().toString());
} else {
preferences = {};
console.log('invalid - ' + this.getUri().toString());
}
this.handlePreferenceChanges(preferences);
} catch (e) {
console.error(`Failed to load preferences from '${this.getUri()}'.`, e);
}
Expand Down

0 comments on commit a8da83d

Please sign in to comment.