提交 4a3c868b 编写于 作者: J Johannes Rieken

use URI in favour of URL

上级 a436a255
......@@ -300,7 +300,13 @@ export class URL extends URI implements objects.IEqualable {
}
public static fromUri(value: URI): URL {
return value && new URL(value);
if (!value) {
return <any>value;
} else if (value instanceof URL) {
return value;
} else {
return new URL(value);
}
}
private _spec:string;
......@@ -309,7 +315,7 @@ export class URL extends URI implements objects.IEqualable {
constructor(spec: string);
constructor(spec: URI);
constructor(stringOrURI: any) {
constructor(stringOrURI: string|URI) {
super();
assert.ok(!!stringOrURI, 'spec must not be null');
if(typeof stringOrURI === 'string') {
......
......@@ -13,7 +13,7 @@ import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import standaloneServices = require('vs/editor/browser/standalone/standaloneServices');
import Platform = require('vs/platform/platform');
import Network = require('vs/base/common/network');
import URI from 'vs/base/common/uri';
import Model = require('vs/editor/common/model/model');
import Lifecycle = require('vs/base/common/lifecycle');
import MonarchTypes = require('vs/editor/common/modes/monarch/monarchTypes');
......@@ -346,7 +346,7 @@ function prepareServices(domElement: HTMLElement, services: standaloneServices.I
};
}
function createModelWithRegistryMode(modelService:IModelService, modeService:IModeService, value:string, modeName:string, associatedResource?:Network.URL): EditorCommon.IModel {
function createModelWithRegistryMode(modelService:IModelService, modeService:IModeService, value:string, modeName:string, associatedResource?:URI): EditorCommon.IModel {
var modeInformation = modeService.lookup(modeName);
if (modeInformation.length > 0) {
// Force usage of the first existing mode
......@@ -362,13 +362,13 @@ function createModelWithRegistryMode(modelService:IModelService, modeService:IMo
return modelService.createModel(value, modeService.getOrCreateMode(modeName), associatedResource);
}
export function createModel(value:string, mode:string|MonarchTypes.ILanguage|Modes.IMode, associatedResource?:Network.URL|string): EditorCommon.IModel {
export function createModel(value:string, mode:string|MonarchTypes.ILanguage|Modes.IMode, associatedResource?:URI|string): EditorCommon.IModel {
startup.initStaticServicesIfNecessary();
var modelService = standaloneServices.ensureStaticPlatformServices(null).modelService;
var resource:Network.URL;
var resource:URI;
if (typeof associatedResource === 'string') {
resource = new Network.URL(associatedResource);
resource = URI.parse(associatedResource);
} else {
// must be a URL
resource = associatedResource;
......
......@@ -1766,7 +1766,6 @@ export interface IModel extends IEditableTextModel, ITextModelWithMarkers, IToke
onBeforeDetached(): void;
getURL(): URL;
getModeId(): string;
/**
......
......@@ -36,7 +36,7 @@ export class AbstractMirrorModel extends TextModelWithTokens implements EditorCo
}
this._setVersionId(versionId);
this._associatedResource = associatedResource && URL.fromUri(associatedResource);
this._associatedResource = URL.fromUri(associatedResource);
this._extraProperties = properties;
}
......
......@@ -10,6 +10,7 @@ import {TextModel} from 'vs/editor/common/model/textModel';
import {EditableTextModel} from 'vs/editor/common/model/editableTextModel';
import EditorCommon = require('vs/editor/common/editorCommon');
import {URL} from 'vs/base/common/network';
import URI from 'vs/base/common/uri';
import Objects = require('vs/base/common/objects');
import {IDisposable} from 'vs/base/common/lifecycle';
......@@ -56,7 +57,7 @@ export class Model extends EditableTextModel implements EditorCommon.IModel {
* The resource associated with this model. If the value is not provided an
* unique in memory URL is constructed as the associated resource.
*/
constructor(rawText:string, modeOrPromise:IMode|TPromise<IMode>, associatedResource:URL=null) {
constructor(rawText:string, modeOrPromise:IMode|TPromise<IMode>, associatedResource:URI=null) {
super([
EditorCommon.EventType.ModelPropertiesChanged,
EditorCommon.EventType.ModelDispose
......@@ -67,10 +68,11 @@ export class Model extends EditableTextModel implements EditorCommon.IModel {
this.id = '$model' + MODEL_ID;
if (typeof associatedResource === 'undefined' || associatedResource === null) {
associatedResource = new URL('inmemory://model/' + MODEL_ID);
this._associatedResource = new URL('inmemory://model/' + MODEL_ID);
} else {
this._associatedResource = URL.fromUri(associatedResource);
}
this._associatedResource = associatedResource;
if (aliveModels[String(this._associatedResource)]) {
throw new Error('Cannot instantiate a second Model with the same URI!');
......@@ -83,10 +85,6 @@ export class Model extends EditableTextModel implements EditorCommon.IModel {
// console.log('ALIVE MODELS: ' + Object.keys(aliveModels).join('\n'));
}
public getURL(): URL {
return this._associatedResource;
}
public getModeId(): string {
return this.getMode().getId();
}
......
......@@ -18,7 +18,6 @@ import {AllWorkersAttr} from 'vs/platform/thread/common/threadService';
import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {EventSource} from 'vs/base/common/eventSource';
import URI from 'vs/base/common/uri';
import {URL} from 'vs/base/common/network';
import Severity from 'vs/base/common/severity';
import {EventProvider} from 'vs/base/common/eventProvider';
import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';
......@@ -221,7 +220,7 @@ export class ModelServiceImpl implements IModelService {
private _createModelData(value:string, modeOrPromise:TPromise<Modes.IMode>|Modes.IMode, resource: URI): ModelData {
// create & save the model
let model = new Model(value, modeOrPromise, resource && URL.fromUri(resource));
let model = new Model(value, modeOrPromise, resource);
let modelId = MODEL_ID(model.getAssociatedResource());
if (this._models[modelId]) {
......@@ -390,7 +389,7 @@ export class ModelServiceWorkerHelper {
public $_acceptNewModel(data:IRawModelData): TPromise<void> {
// Create & insert the mirror model eagerly in the resource service
let mirrorModel = new MirrorModel(this._resourceService, data.versionId, data.value, null, URL.fromUri(data.url), data.properties);
let mirrorModel = new MirrorModel(this._resourceService, data.versionId, data.value, null, data.url, data.properties);
this._resourceService.insert(mirrorModel.getAssociatedResource(), mirrorModel);
// Block worker execution until the mode is instantiated
......
......@@ -10,7 +10,6 @@ import * as Objects from 'vs/base/common/objects';
import * as Strings from 'vs/base/common/strings';
import * as Assert from 'vs/base/common/assert';
import * as Paths from 'vs/base/common/paths';
import * as NetWork from 'vs/base/common/network';
import * as Types from 'vs/base/common/types';
import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri';
......@@ -171,7 +170,7 @@ export function getResource(filename: string, matcher: ProblemMatcher): URI {
if (fullPath[0] !== '/') {
fullPath = '/' + fullPath;
}
return NetWork.URL.fromValue('file://' + fullPath);
return URI.parse('file://' + fullPath);
}
export interface ILineMatcher {
......
......@@ -7,17 +7,16 @@
import * as assert from 'assert';
import {Match, FileMatch, SearchResult} from 'vs/workbench/parts/search/common/searchModel';
import model = require('vs/editor/common/model/model');
import {URL} from 'vs/base/common/network';
import {EventSource} from 'vs/base/common/eventSource';
import {IModel} from 'vs/editor/common/editorCommon';
import uri from 'vs/base/common/uri';
import URI from 'vs/base/common/uri';
import {create} from 'vs/platform/instantiation/common/instantiationService';
import {TestContextService} from 'vs/workbench/test/browser/servicesTestUtils';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IFileMatch} from 'vs/platform/search/common/search';
function toUri(path: string): uri {
return uri.file('C:\\' + path);
function toUri(path: string): URI {
return URI.file('C:\\' + path);
}
suite('Search - Model', () => {
......@@ -27,7 +26,7 @@ suite('Search - Model', () => {
setup(() => {
let event = new EventSource<any>();
oneModel = new model.Model('line1\nline2\nline3', null, URL.fromValue('file:///folder/file.txt'));
oneModel = new model.Model('line1\nline2\nline3', null, URI.parse('file:///folder/file.txt'));
instantiation = create({
modelService: {
getModel: () => oneModel,
......@@ -85,7 +84,7 @@ suite('Search - Model', () => {
let raw: IFileMatch[] = [];
for (let i = 0; i < 10; i++) {
raw.push({
resource: uri.parse('file://c:/' + i),
resource: URI.parse('file://c:/' + i),
lineMatches: [{
preview: String(i),
lineNumber: 1,
......
......@@ -9,7 +9,6 @@ import * as assert from 'assert';
import {setUnexpectedErrorHandler, errorHandler} from 'vs/base/common/errors';
import {create} from 'vs/base/common/types';
import URI from 'vs/base/common/uri';
import {URL} from 'vs/base/common/network';
import {TPromise} from 'vs/base/common/winjs.base';
import {PluginHostDocument} from 'vs/workbench/api/common/pluginHostDocuments';
import * as types from 'vs/workbench/api/common/pluginHostTypes';
......@@ -49,7 +48,7 @@ const model: EditorCommon.IModel = new EditorModel(
'This is the third line',
].join('\n'),
undefined,
URL.fromUri(URI.parse('far://testing/file.b')));
URI.parse('far://testing/file.b'));
let extHost: ExtHostLanguageFeatures;
let mainThread: MainThreadLanguageFeatures;
......
......@@ -9,7 +9,6 @@ import * as assert from 'assert';
import {setUnexpectedErrorHandler, errorHandler} from 'vs/base/common/errors';
import {create} from 'vs/base/common/types';
import URI from 'vs/base/common/uri';
import {URL} from 'vs/base/common/network';
import {TPromise} from 'vs/base/common/winjs.base';
import {PluginHostDocument} from 'vs/workbench/api/common/pluginHostDocuments';
import * as types from 'vs/workbench/api/common/pluginHostTypes';
......@@ -47,7 +46,7 @@ const model: EditorCommon.IModel = new EditorModel(
'This is the third line',
].join('\n'),
undefined,
URL.fromUri(URI.parse('far://testing/file.a')));
URI.parse('far://testing/file.a'));
let extHost: ExtHostLanguageFeatures;
let mainThread: MainThreadLanguageFeatures;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册