Skip to content

Commit

Permalink
Use URI for ExtHostDocumentsShape methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 8, 2018
1 parent 5b1d34e commit f322bae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/vs/workbench/api/electron-browser/mainThreadDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {

this._toDispose.push(textFileService.models.onModelSaved(e => {
if (this._shouldHandleFileEvent(e)) {
this._proxy.$acceptModelSaved(e.resource.toString());
this._proxy.$acceptModelSaved(e.resource);
}
}));
this._toDispose.push(textFileService.models.onModelReverted(e => {
if (this._shouldHandleFileEvent(e)) {
this._proxy.$acceptDirtyStateChanged(e.resource.toString(), false);
this._proxy.$acceptDirtyStateChanged(e.resource, false);
}
}));
this._toDispose.push(textFileService.models.onModelDirty(e => {
if (this._shouldHandleFileEvent(e)) {
this._proxy.$acceptDirtyStateChanged(e.resource.toString(), true);
this._proxy.$acceptDirtyStateChanged(e.resource, true);
}
}));

Expand Down Expand Up @@ -143,7 +143,7 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
let modelUrl = model.uri;
this._modelIsSynced[modelUrl.toString()] = true;
this._modelToDisposeMap[modelUrl.toString()] = model.onDidChangeContent((e) => {
this._proxy.$acceptModelChanged(modelUrl.toString(), e, this._textFileService.isDirty(modelUrl));
this._proxy.$acceptModelChanged(modelUrl, e, this._textFileService.isDirty(modelUrl));
});
}

Expand All @@ -153,7 +153,7 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
if (!this._modelIsSynced[modelUrl.toString()]) {
return;
}
this._proxy.$acceptModelModeChanged(model.uri.toString(), oldModeId, model.getLanguageIdentifier().language);
this._proxy.$acceptModelModeChanged(model.uri, oldModeId, model.getLanguageIdentifier().language);
}

private _onModelRemoved(modelUrl: URI): void {
Expand Down Expand Up @@ -227,7 +227,7 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
throw new Error(`expected URI ${resource.toString()} to have come to LIFE`);
}

this._proxy.$acceptDirtyStateChanged(resource.toString(), true); // mark as dirty
this._proxy.$acceptDirtyStateChanged(resource, true); // mark as dirty

return resource;
});
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ export interface IModelAddedData {
isDirty: boolean;
}
export interface ExtHostDocumentsShape {
$acceptModelModeChanged(strURL: string, oldModeId: string, newModeId: string): void;
$acceptModelSaved(strURL: string): void;
$acceptDirtyStateChanged(strURL: string, isDirty: boolean): void;
$acceptModelChanged(strURL: string, e: IModelChangedEvent, isDirty: boolean): void;
$acceptModelModeChanged(strURL: UriComponents, oldModeId: string, newModeId: string): void;
$acceptModelSaved(strURL: UriComponents): void;
$acceptDirtyStateChanged(strURL: UriComponents, isDirty: boolean): void;
$acceptModelChanged(strURL: UriComponents, e: IModelChangedEvent, isDirty: boolean): void;
}

export interface ExtHostDocumentSaveParticipantShape {
Expand Down
20 changes: 14 additions & 6 deletions src/vs/workbench/api/node/extHostDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

import Event, { Emitter } from 'vs/base/common/event';
import URI from 'vs/base/common/uri';
import URI, { UriComponents } from 'vs/base/common/uri';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as TypeConverters from './extHostTypeConverters';
import { TPromise } from 'vs/base/common/winjs.base';
Expand Down Expand Up @@ -95,7 +95,9 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
return this._proxy.$tryCreateDocument(options).then(data => URI.revive(data));
}

public $acceptModelModeChanged(strURL: string, oldModeId: string, newModeId: string): void {
public $acceptModelModeChanged(uriComponents: UriComponents, oldModeId: string, newModeId: string): void {
const uri = URI.revive(uriComponents);
const strURL = uri.toString();
let data = this._documentsAndEditors.getDocument(strURL);

// Treat a mode change as a remove + add
Expand All @@ -105,13 +107,17 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
this._onDidAddDocument.fire(data.document);
}

public $acceptModelSaved(strURL: string): void {
public $acceptModelSaved(uriComponents: UriComponents): void {
const uri = URI.revive(uriComponents);
const strURL = uri.toString();
let data = this._documentsAndEditors.getDocument(strURL);
this.$acceptDirtyStateChanged(strURL, false);
this.$acceptDirtyStateChanged(uriComponents, false);
this._onDidSaveDocument.fire(data.document);
}

public $acceptDirtyStateChanged(strURL: string, isDirty: boolean): void {
public $acceptDirtyStateChanged(uriComponents: UriComponents, isDirty: boolean): void {
const uri = URI.revive(uriComponents);
const strURL = uri.toString();
let data = this._documentsAndEditors.getDocument(strURL);
data._acceptIsDirty(isDirty);
this._onDidChangeDocument.fire({
Expand All @@ -120,7 +126,9 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
});
}

public $acceptModelChanged(strURL: string, events: IModelChangedEvent, isDirty: boolean): void {
public $acceptModelChanged(uriComponents: UriComponents, events: IModelChangedEvent, isDirty: boolean): void {
const uri = URI.revive(uriComponents);
const strURL = uri.toString();
let data = this._documentsAndEditors.getDocument(strURL);
data._acceptIsDirty(isDirty);
data.onEvents(events);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
let sub = participant.getOnWillSaveTextDocumentEvent(nullExtensionDescription)(function (e) {

// concurrent change from somewhere
documents.$acceptModelChanged(resource.toString(), {
documents.$acceptModelChanged(resource, {
changes: [{
range: { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 },
rangeLength: undefined,
Expand Down Expand Up @@ -332,7 +332,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
const { resource, edits } = edit;
const uri = URI.revive(resource);
for (const { text, range } of edits) {
documents.$acceptModelChanged(uri.toString(), {
documents.$acceptModelChanged(uri, {
changes: [{
range,
text,
Expand Down

0 comments on commit f322bae

Please sign in to comment.