提交 fe9b6dba 编写于 作者: A Alex Dima

Convert IDeclarationSupport to DefinitionProvider

上级 f739556b
......@@ -410,14 +410,6 @@ export interface DocumentHighlightProvider {
}
/**
* Interface used to find declarations on a symbol
*/
export interface IReference {
resource: URI;
range: editorCommon.IRange;
}
/**
* Interface used to find references to a symbol
*/
......@@ -427,15 +419,18 @@ export interface IReferenceSupport {
* @returns a list of reference of the symbol at the position in the
* given resource.
*/
findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean):TPromise<IReference[]>;
findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean):TPromise<Location[]>;
}
/**
* Interface used to find declarations on a symbol
*/
export interface IDeclarationSupport {
findDeclaration(resource:URI, position:editorCommon.IPosition):TPromise<IReference|IReference[]>;
export class Location {
uri: URI;
range: editorCommon.IRange;
}
export type Definition = Location | Location[];
export interface DefinitionProvider {
provideDefinition(model:editorCommon.IReadOnlyModel, position:editorCommon.IEditorPosition, token:CancellationToken): Definition | Thenable<Definition>;
}
/**
* Interface used to compute an outline
......@@ -712,7 +707,7 @@ export const OutlineRegistry = new LanguageFeatureRegistry<IOutlineSupport>();
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
export const DeclarationRegistry = new LanguageFeatureRegistry<IDeclarationSupport>();
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
export const CodeLensRegistry = new LanguageFeatureRegistry<ICodeLensSupport>();
......
......@@ -25,7 +25,7 @@ import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IReference, DeclarationRegistry} from 'vs/editor/common/modes';
import {Location, DefinitionProviderRegistry} from 'vs/editor/common/modes';
import {tokenizeToHtmlContent} from 'vs/editor/common/modes/textToHtmlTokenizer';
import {ICodeEditor, IEditorMouseEvent, IMouseTarget} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
......@@ -62,7 +62,7 @@ export class DefinitionAction extends EditorAction {
}
public isSupported(): boolean {
return DeclarationRegistry.has(this.editor.getModel()) && super.isSupported();
return DefinitionProviderRegistry.has(this.editor.getModel()) && super.isSupported();
}
public getEnablementState(): boolean {
......@@ -70,7 +70,7 @@ export class DefinitionAction extends EditorAction {
return false;
}
return DeclarationRegistry.has(this.editor.getModel());
return DefinitionProviderRegistry.has(this.editor.getModel());
}
public run(): TPromise<any> {
......@@ -87,19 +87,19 @@ export class DefinitionAction extends EditorAction {
// * remove falsy references
// * remove reference at the current pos
// * collapse ranges to start pos
let result: IReference[] = [];
let result: Location[] = [];
for (let i = 0; i < references.length; i++) {
let reference = references[i];
if (!reference) {
continue;
}
let {resource, range} = reference;
let {uri, range} = reference;
if (!this._configuration.filterCurrent
|| resource.toString() !== model.getAssociatedResource().toString()
|| uri.toString() !== model.getAssociatedResource().toString()
|| !Range.containsPosition(range, pos)) {
result.push({
resource,
uri,
range: Range.collapseToStart(range)
});
}
......@@ -118,7 +118,7 @@ export class DefinitionAction extends EditorAction {
});
}
private _onResult(references: IReference[]) {
private _onResult(references: Location[]) {
if (this._configuration.openInPeek) {
this._openInPeek(this.editor, references);
} else {
......@@ -131,14 +131,14 @@ export class DefinitionAction extends EditorAction {
}
}
private _openReference(reference: IReference, sideBySide: boolean): TPromise<editorCommon.ICommonCodeEditor>{
let {resource, range} = reference;
return this._editorService.openEditor({ resource, options: { selection: range } }, sideBySide).then(editor => {
private _openReference(reference: Location, sideBySide: boolean): TPromise<editorCommon.ICommonCodeEditor>{
let {uri, range} = reference;
return this._editorService.openEditor({ resource:uri, options: { selection: range } }, sideBySide).then(editor => {
return <editorCommon.IEditor> editor.getControl();
});
}
private _openInPeek(target: editorCommon.ICommonCodeEditor, references: IReference[]) {
private _openInPeek(target: editorCommon.ICommonCodeEditor, references: Location[]) {
let controller = ReferencesController.getController(target);
controller.toggleWidget(target.getSelection(), TPromise.as(new ReferencesModel(references)), {
getMetaTitle: (model) => {
......@@ -288,7 +288,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
// Single result
else {
let result = results[0];
this.editorService.resolveEditorModel({ resource: result.resource }).then(model => {
this.editorService.resolveEditorModel({ resource: result.uri }).then(model => {
let source: string;
if (model && model.textEditorModel) {
......@@ -429,10 +429,10 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
(browser.isIE11orEarlier || mouseEvent.event.detail <= 1) && // IE does not support event.detail properly
mouseEvent.target.type === editorCommon.MouseTargetType.CONTENT_TEXT &&
(mouseEvent.event[GotoDefinitionWithMouseEditorContribution.TRIGGER_MODIFIER] || (withKey && withKey.keyCode === GotoDefinitionWithMouseEditorContribution.TRIGGER_KEY_VALUE)) &&
DeclarationRegistry.has(this.editor.getModel());
DefinitionProviderRegistry.has(this.editor.getModel());
}
private findDefinition(target: IMouseTarget): TPromise<IReference[]> {
private findDefinition(target: IMouseTarget): TPromise<Location[]> {
let model = this.editor.getModel();
if (!model) {
return TPromise.as(null);
......
......@@ -7,19 +7,21 @@
import {onUnexpectedError} from 'vs/base/common/errors';
import {TPromise} from 'vs/base/common/winjs.base';
import {IReadOnlyModel, IPosition} from 'vs/editor/common/editorCommon';
import {IReadOnlyModel, IEditorPosition} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {DeclarationRegistry} from 'vs/editor/common/modes';
import {IReference} from 'vs/editor/common/modes';
import {DefinitionProviderRegistry} from 'vs/editor/common/modes';
import {Location} from 'vs/editor/common/modes';
import {asWinJsPromise} from 'vs/base/common/async';
export function getDeclarationsAtPosition(model: IReadOnlyModel, position: IPosition): TPromise<IReference[]> {
export function getDeclarationsAtPosition(model: IReadOnlyModel, position: IEditorPosition): TPromise<Location[]> {
const resource = model.getAssociatedResource();
const provider = DeclarationRegistry.ordered(model);
const provider = DefinitionProviderRegistry.ordered(model);
// get results
const promises = provider.map((provider, idx) => {
return provider.findDeclaration(resource, position).then(result => {
return asWinJsPromise((token) => {
return provider.provideDefinition(model, position, token);
}).then(result => {
return result;
}, err => {
onUnexpectedError(err);
......@@ -27,7 +29,7 @@ export function getDeclarationsAtPosition(model: IReadOnlyModel, position: IPosi
});
return TPromise.join(promises).then(allReferences => {
let result: IReference[] = [];
let result: Location[] = [];
for (let references of allReferences) {
if (Array.isArray(references)) {
result.push(...references);
......
......@@ -18,7 +18,7 @@ import {EditorAction} from 'vs/editor/common/editorAction';
import {Behaviour} from 'vs/editor/common/editorActionEnablement';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {IReference, ReferenceSearchRegistry} from 'vs/editor/common/modes';
import {Location, ReferenceSearchRegistry} from 'vs/editor/common/modes';
import {IPeekViewService, getOuterEditor} from 'vs/editor/contrib/zoneWidget/browser/peekViewWidget';
import {findReferences} from '../common/referenceSearch';
import {ReferenceWidget} from './referencesWidget';
......@@ -104,7 +104,7 @@ let findReferencesCommand: ICommandHandler = (accessor:ServicesAccessor, resourc
});
};
let showReferencesCommand: ICommandHandler = (accessor:ServicesAccessor, resource:URI, position:editorCommon.IPosition, references:IReference[]) => {
let showReferencesCommand: ICommandHandler = (accessor:ServicesAccessor, resource:URI, position:editorCommon.IPosition, references:Location[]) => {
if (!(resource instanceof URI)) {
throw new Error('illegal argument, uri expected');
}
......
......@@ -184,10 +184,10 @@ export class ReferencesController implements editorCommon.IEditorContribution {
private _gotoReference(ref: OneReference): void {
this._ignoreModelChangeEvent = true;
const {resource, range} = ref;
const {uri, range} = ref;
this._editorService.openEditor({
resource,
resource: uri,
options: { selection: range }
}).done(openedEditor => {
this._ignoreModelChangeEvent = false;
......@@ -214,9 +214,9 @@ export class ReferencesController implements editorCommon.IEditorContribution {
}
private _openReference(ref: OneReference, sideBySide: boolean): void {
const {resource, range} = ref;
const {uri, range} = ref;
this._editorService.openEditor({
resource,
resource: uri,
options: { selection: range }
}, sideBySide);
......
......@@ -14,7 +14,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {Range} from 'vs/editor/common/core/range';
import {IModel, IPosition, IRange} from 'vs/editor/common/editorCommon';
import {IReference} from 'vs/editor/common/modes';
import {Location} from 'vs/editor/common/modes';
export class OneReference {
......@@ -40,8 +40,8 @@ export class OneReference {
return this._parent;
}
public get resource(): URI {
return this._parent.resource;
public get uri(): URI {
return this._parent.uri;
}
public get name(): string {
......@@ -96,12 +96,12 @@ export class FileReferences {
private _preview: FilePreview;
private _resolved: boolean;
constructor(private _parent: ReferencesModel, private _resource: URI) {
constructor(private _parent: ReferencesModel, private _uri: URI) {
this._children = [];
}
public get id(): string {
return this._resource.toString();
return this._uri.toString();
}
public get parent(): ReferencesModel {
......@@ -112,16 +112,16 @@ export class FileReferences {
return this._children;
}
public get resource(): URI {
return this._resource;
public get uri(): URI {
return this._uri;
}
public get name(): string {
return basename(this.resource.fsPath);
return basename(this.uri.fsPath);
}
public get directory(): string {
return dirname(this.resource.fsPath);
return dirname(this.uri.fsPath);
}
public get preview(): FilePreview {
......@@ -134,7 +134,7 @@ export class FileReferences {
return TPromise.as(this);
}
return editorService.resolveEditorModel({ resource: this._resource }).then(model => {
return editorService.resolveEditorModel({ resource: this._uri }).then(model => {
this._preview = new FilePreview((<IModel>model.textEditorModel).getValue());
this._resolved = true;
return this;
......@@ -150,16 +150,16 @@ export class ReferencesModel {
onDidChangeReferenceRange: Event<OneReference> = fromEventEmitter<OneReference>(this._eventBus, 'ref/changed');
constructor(references: IReference[]) {
constructor(references: Location[]) {
// grouping and sorting
references.sort(ReferencesModel._compareReferences);
let current: FileReferences;
for (let ref of references) {
if (!current || current.resource.toString() !== ref.resource.toString()) {
if (!current || current.uri.toString() !== ref.uri.toString()) {
// new group
current = new FileReferences(this, ref.resource);
current = new FileReferences(this, ref.uri);
this.groups.push(current);
}
......@@ -206,7 +206,7 @@ export class ReferencesModel {
let candidate: OneReference;
let candiateDist: number;
for (let ref of this._references) {
if (ref.resource.toString() !== resource.toString()) {
if (ref.uri.toString() !== resource.toString()) {
continue;
}
......@@ -227,10 +227,10 @@ export class ReferencesModel {
return candidate || this._references[0];
}
private static _compareReferences(a: IReference, b: IReference): number {
if (a.resource.toString() < b.resource.toString()) {
private static _compareReferences(a: Location, b: Location): number {
if (a.uri.toString() < b.uri.toString()) {
return -1;
} else if (a.resource.toString() > b.resource.toString()) {
} else if (a.uri.toString() > b.uri.toString()) {
return 1;
} else {
return Range.compareRangesUsingStarts(a.range, b.range);
......
......@@ -73,7 +73,7 @@ class DecorationsManager implements IDisposable {
}
for(var i = 0, len = this.model.groups.length; i < len; i++) {
if(this.model.groups[i].resource.toString() === model.getAssociatedResource().toString()) {
if(this.model.groups[i].uri.toString() === model.getAssociatedResource().toString()) {
this._addDecorations(this.model.groups[i]);
return;
}
......@@ -351,7 +351,7 @@ class Renderer extends LegacyRenderer {
/* tslint:disable:no-unused-expression */
new LeftRightWidget(fileReferencesContainer, (left: HTMLElement) => {
var resource = fileReferences.resource;
var resource = fileReferences.uri;
new FileLabel(left, resource, this._contextService);
return <IDisposable> null;
......@@ -685,14 +685,14 @@ export class ReferenceWidget extends PeekViewWidget {
private _revealReference(reference: OneReference) {
// Update widget header
if (reference.resource.scheme !== Schemas.inMemory) {
if (reference.uri.scheme !== Schemas.inMemory) {
this.setTitle(reference.name, getPathLabel(reference.directory, this._contextService));
} else {
this.setTitle(nls.localize('peekView.alternateTitle', "References"));
}
return TPromise.join([
this._editorService.resolveEditorModel({ resource: reference.resource }),
this._editorService.resolveEditorModel({ resource: reference.uri }),
this._tree.reveal(reference)
]).then(values => {
if (!this._model) {
......
......@@ -9,15 +9,15 @@ import {onUnexpectedError} from 'vs/base/common/errors';
import {TPromise} from 'vs/base/common/winjs.base';
import {IReadOnlyModel, IPosition} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {IReference, ReferenceSearchRegistry} from 'vs/editor/common/modes';
import {Location, ReferenceSearchRegistry} from 'vs/editor/common/modes';
export function findReferences(model: IReadOnlyModel, position: IPosition): TPromise<IReference[]> {
export function findReferences(model: IReadOnlyModel, position: IPosition): TPromise<Location[]> {
// collect references from all providers
const promises = ReferenceSearchRegistry.ordered(model).map(provider => {
return provider.findReferences(model.getAssociatedResource(), position, true).then(result => {
if (Array.isArray(result)) {
return <IReference[]> result;
return <Location[]> result;
}
}, err => {
onUnexpectedError(err);
......@@ -25,7 +25,7 @@ export function findReferences(model: IReadOnlyModel, position: IPosition): TPro
});
return TPromise.join(promises).then(references => {
let result: IReference[] = [];
let result: Location[] = [];
for (let ref of references) {
if (ref) {
result.push(...ref);
......
......@@ -19,7 +19,6 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import {IThreadService, ThreadAffinity} from 'vs/platform/thread/common/thread';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {TokenizationSupport} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {CancellationToken} from 'vs/base/common/cancellation';
import {wireCancellationToken} from 'vs/base/common/async';
export enum States {
......@@ -327,18 +326,35 @@ export class CSSMode extends AbstractMode {
this.inplaceReplaceSupport = this;
this.configSupport = this;
// Modes.OccurrencesRegistry.register(this.getId(), this);
modes.HoverProviderRegistry.register(this.getId(), this);
// Modes.ReferenceSearchRegistry.register(this.getId(), this);
// modes.DocumentHighlightProviderRegistry.register(this.getId(), {
// provideDocumentHighlights: (model, position, token): Thenable<modes.DocumentHighlight[]> => {
// return wireCancellationToken(token, this._provideDocumentHighlights(model.getAssociatedResource(), position));
// }
// });
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
// modes.ReferenceSearchRegistry.register(this.getId(), this);
modes.OutlineRegistry.register(this.getId(), this);
// Modes.DeclarationRegistry.register(this.getId(), {
// findDeclaration: (resource, position) => this.findDeclaration(resource, position)
// modes.DefinitionProviderRegistry.register(this.getId(), {
// provideDefinition: (model, position, token): Thenable<modes.Definition> => {
// return wireCancellationToken(token, this._provideDefinition(model.getAssociatedResource(), position));
// }
// });
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: [' ', ':'],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
});
modes.QuickFixRegistry.register(this.getId(), this);
......@@ -378,37 +394,28 @@ export class CSSMode extends AbstractMode {
return this._worker((w) => w.enableValidator());
}
public provideDocumentHighlights(model: editorCommon.IReadOnlyModel, position: editorCommon.IEditorPosition, token: CancellationToken): Thenable<modes.DocumentHighlight[]> {
return wireCancellationToken(token, this._provideDocumentHighlights(model.getAssociatedResource(), position));
}
static $_provideDocumentHighlights = OneWorkerAttr(CSSMode, CSSMode.prototype._provideDocumentHighlights);
private _provideDocumentHighlights(resource:URI, position:editorCommon.IPosition): WinJS.TPromise<modes.DocumentHighlight[]> {
return this._worker((w) => w.provideDocumentHighlights(resource, position));
}
public provideCompletionItems(model:editorCommon.IReadOnlyModel, position:editorCommon.IEditorPosition, token:CancellationToken): Thenable<modes.ISuggestResult[]> {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
static $_provideCompletionItems = OneWorkerAttr(CSSMode, CSSMode.prototype._provideCompletionItems);
private _provideCompletionItems(resource:URI, position:editorCommon.IPosition):WinJS.TPromise<modes.ISuggestResult[]> {
return this._worker((w) => w.provideCompletionItems(resource, position));
}
static $findDeclaration = OneWorkerAttr(CSSMode, CSSMode.prototype.findDeclaration);
public findDeclaration(resource:URI, position:editorCommon.IPosition):WinJS.TPromise<modes.IReference> {
return this._worker((w) => w.findDeclaration(resource, position));
static $_provideDefinition = OneWorkerAttr(CSSMode, CSSMode.prototype._provideDefinition);
private _provideDefinition(resource:URI, position:editorCommon.IPosition):WinJS.TPromise<modes.Definition> {
return this._worker((w) => w.provideDefinition(resource, position));
}
public provideHover(model:editorCommon.IReadOnlyModel, position:editorCommon.IEditorPosition, token:CancellationToken): Thenable<modes.Hover> {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
static $_provideHover = OneWorkerAttr(CSSMode, CSSMode.prototype._provideHover);
private _provideHover(resource:URI, position:editorCommon.IPosition): WinJS.TPromise<modes.Hover> {
return this._worker((w) => w.provideHover(resource, position));
}
static $findReferences = OneWorkerAttr(CSSMode, CSSMode.prototype.findReferences);
public findReferences(resource:URI, position:editorCommon.IPosition):WinJS.TPromise<modes.IReference[]> {
public findReferences(resource:URI, position:editorCommon.IPosition):WinJS.TPromise<modes.Location[]> {
return this._worker((w) => w.findReferences(resource, position));
}
......
......@@ -13,8 +13,8 @@ import languageService = require('vs/languages/css/common/services/cssLanguageSe
import languageFacts = require('vs/languages/css/common/services/languageFacts');
import occurrences = require('./services/occurrences');
import cssIntellisense = require('vs/languages/css/common/services/intelliSense');
import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import editorCommon = require('vs/editor/common/editorCommon');
import modes = require('vs/editor/common/modes');
import nodes = require('vs/languages/css/common/parser/cssNodes');
import _level = require('vs/languages/css/common/level');
import parser = require('vs/languages/css/common/parser/cssParser');
......@@ -59,7 +59,7 @@ export class CSSWorker {
this.validationEnabled = true;
}
public navigateValueSet(resource:URI, range:EditorCommon.IRange, up:boolean):winjs.TPromise<Modes.IInplaceReplaceSupportResult> {
public navigateValueSet(resource:URI, range:editorCommon.IRange, up:boolean):winjs.TPromise<modes.IInplaceReplaceSupportResult> {
return this.languageService.join().then(() => {
let model = this.resourceService.get(resource);
......@@ -99,7 +99,7 @@ export class CSSWorker {
nextIdx = len - 1;
}
}
let result:Modes.IInplaceReplaceSupportResult = {
let result:modes.IInplaceReplaceSupportResult = {
value: values[nextIdx],
range: this._range(node, model)
};
......@@ -108,7 +108,7 @@ export class CSSWorker {
}
// if none matches, take the first one
if (values.length > 0) {
let result:Modes.IInplaceReplaceSupportResult = {
let result:modes.IInplaceReplaceSupportResult = {
value: values[0],
range: this._range(node, model)
};
......@@ -175,7 +175,7 @@ export class CSSWorker {
});
}
private _createMarkerData(model: EditorCommon.IMirrorModel, marker: nodes.IMarker): IMarkerData {
private _createMarkerData(model: editorCommon.IMirrorModel, marker: nodes.IMarker): IMarkerData {
let range = model.getRangeFromOffsetAndLength(marker.getOffset(), marker.getLength());
return <IMarkerData> {
code: marker.getRule().id,
......@@ -196,11 +196,11 @@ export class CSSWorker {
return new cssIntellisense.CSSIntellisense();
}
public provideCompletionItems(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.ISuggestResult[]> {
public provideCompletionItems(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.ISuggestResult[]> {
return this.doSuggest(resource, position).then(value => filterSuggestions(value));
}
private doSuggest(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.ISuggestResult> {
private doSuggest(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.ISuggestResult> {
return this.languageService.join().then(() => {
......@@ -211,17 +211,17 @@ export class CSSWorker {
}
public getOutline(resource:URI):winjs.TPromise<Modes.IOutlineEntry[]> {
public getOutline(resource:URI):winjs.TPromise<modes.IOutlineEntry[]> {
return this.languageService.join().then(() => {
let model = this.resourceService.get(resource),
stylesheet = this.languageService.getStylesheet(resource),
result:Modes.IOutlineEntry[] = [];
result:modes.IOutlineEntry[] = [];
stylesheet.accept((node) => {
let entry:Modes.IOutlineEntry = {
let entry:modes.IOutlineEntry = {
label: null,
type: 'rule',
range: null,
......@@ -257,7 +257,7 @@ export class CSSWorker {
});
}
public provideHover(resource:URI, position:EditorCommon.IPosition): winjs.TPromise<Modes.Hover> {
public provideHover(resource:URI, position:editorCommon.IPosition): winjs.TPromise<modes.Hover> {
return this.languageService.join().then(() => {
......@@ -296,7 +296,7 @@ export class CSSWorker {
});
}
public findDeclaration(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.IReference> {
public provideDefinition(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.Location> {
return this.languageService.join().then(() => {
......@@ -308,14 +308,14 @@ export class CSSWorker {
return null;
}
return <Modes.IReference> {
resource: resource,
return {
uri: resource,
range: this._range(node, model, true)
};
});
}
public provideDocumentHighlights(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.DocumentHighlight[]> {
public provideDocumentHighlights(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.DocumentHighlight[]> {
return this.languageService.join().then(() => {
......@@ -332,7 +332,7 @@ export class CSSWorker {
});
}
public findReferences(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.IReference[]> {
public findReferences(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.Location[]> {
return this.languageService.join().then(() => {
let model = this.resourceService.get(resource),
......@@ -340,8 +340,8 @@ export class CSSWorker {
nodes = occurrences.findOccurrences(this.languageService.getStylesheet(resource), offset);
return nodes.map((occurrence) => {
return <Modes.IReference> {
resource: model.getAssociatedResource(),
return {
uri: model.getAssociatedResource(),
range: this._range(occurrence.node, model)
};
});
......@@ -354,7 +354,7 @@ export class CSSWorker {
let model = this.resourceService.get(resource),
styleSheet = this.languageService.getStylesheet(resource),
result:{range:EditorCommon.IRange; value:string; }[] = [];
result:{range:editorCommon.IRange; value:string; }[] = [];
styleSheet.accept((node) => {
if (languageFacts.isColorValue(node)) {
......@@ -370,7 +370,7 @@ export class CSSWorker {
});
}
_range(node:{offset:number; length:number;}, model:EditorCommon.IMirrorModel, empty:boolean = false):EditorCommon.IRange {
_range(node:{offset:number; length:number;}, model:editorCommon.IMirrorModel, empty:boolean = false):editorCommon.IRange {
if (empty) {
let position = model.getPositionFromOffset(node.offset);
return {
......@@ -384,10 +384,10 @@ export class CSSWorker {
}
}
private getFixesForUnknownProperty(property: nodes.Property, marker: IMarker) : Modes.IQuickFix[] {
private getFixesForUnknownProperty(property: nodes.Property, marker: IMarker) : modes.IQuickFix[] {
let propertyName = property.getName();
let result: Modes.IQuickFix[] = [];
let result: modes.IQuickFix[] = [];
for (let p in languageFacts.getProperties()) {
let score = strings.difference(propertyName, p);
if (score >= propertyName.length / 2 /*score_lim*/) {
......@@ -410,7 +410,7 @@ export class CSSWorker {
return result.slice(0, 3 /*max_result*/);
}
private appendFixesForMarker(bucket: Modes.IQuickFix[], marker: IMarker): void {
private appendFixesForMarker(bucket: modes.IQuickFix[], marker: IMarker): void {
if ((<IMarker>marker).code !== lintRules.Rules.UnknownProperty.id) {
return;
......@@ -432,10 +432,10 @@ export class CSSWorker {
}
}
public getQuickFixes(resource: URI, range: EditorCommon.IRange): winjs.TPromise<Modes.IQuickFix[]> {
public getQuickFixes(resource: URI, range: editorCommon.IRange): winjs.TPromise<modes.IQuickFix[]> {
return this.languageService.join().then(() => {
const result: Modes.IQuickFix[] = [];
const result: modes.IQuickFix[] = [];
this.markerService.read({ resource })
.filter(marker => Range.containsRange(range, marker))
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import Modes = require('vs/editor/common/modes');
import modes = require('vs/editor/common/modes');
import htmlMode = require('vs/languages/html/common/html');
import handlebarsTokenTypes = require('vs/languages/handlebars/common/handlebarsTokenTypes');
import htmlWorker = require('vs/languages/html/common/htmlWorker');
......@@ -14,6 +14,7 @@ import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {createWordRegExp} from 'vs/editor/common/modes/abstractMode';
import {ILeavingNestedModeData} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {wireCancellationToken} from 'vs/base/common/async';
export enum States {
HTML,
......@@ -23,7 +24,7 @@ export enum States {
export class HandlebarsState extends htmlMode.State {
constructor(mode:Modes.IMode,
constructor(mode:modes.IMode,
public kind:htmlMode.States,
public handlebarsKind:States,
public lastTagName:string,
......@@ -39,7 +40,7 @@ export class HandlebarsState extends htmlMode.State {
return new HandlebarsState(this.getMode(), this.kind, this.handlebarsKind, this.lastTagName, this.lastAttributeName, this.embeddedContentType, this.attributeValueQuote, this.attributeValue);
}
public equals(other:Modes.IState):boolean {
public equals(other:modes.IState):boolean {
if (other instanceof HandlebarsState) {
return (
super.equals(other)
......@@ -48,7 +49,7 @@ export class HandlebarsState extends htmlMode.State {
return false;
}
public tokenize(stream:Modes.IStream) : Modes.ITokenizationResult {
public tokenize(stream:modes.IStream) : modes.ITokenizationResult {
switch(this.handlebarsKind) {
case States.HTML:
if (stream.advanceIfString('{{{').length > 0) {
......@@ -107,7 +108,7 @@ export class HandlebarsState extends htmlMode.State {
export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
constructor(
descriptor:Modes.IModeDescriptor,
descriptor:modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IModeService modeService: IModeService,
@IThreadService threadService: IThreadService
......@@ -116,17 +117,30 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
}
protected _registerSupports(): void {
Modes.HoverProviderRegistry.register(this.getId(), this);
Modes.ReferenceSearchRegistry.register(this.getId(), this);
Modes.SuggestRegistry.register(this.getId(), {
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
modes.ReferenceSearchRegistry.register(this.getId(), this);
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: ['.', ':', '<', '"', '=', '/'],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
});
modes.DocumentHighlightProviderRegistry.register(this.getId(), {
provideDocumentHighlights: (model, position, token): Thenable<modes.DocumentHighlight[]> => {
return wireCancellationToken(token, this._provideDocumentHighlights(model.getAssociatedResource(), position));
}
});
Modes.DocumentHighlightProviderRegistry.register(this.getId(), this);
}
protected _createRichEditSupport(): Modes.IRichEditSupport {
protected _createRichEditSupport(): modes.IRichEditSupport {
return new RichEditSupport(this.getId(), null, {
wordPattern: createWordRegExp('#-?%'),
......@@ -164,21 +178,21 @@ export class HandlebarsMode extends htmlMode.HTMLMode<htmlWorker.HTMLWorker> {
{
beforeText: new RegExp(`<(?!(?:${htmlMode.EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
afterText: /^<\/(\w[\w\d]*)\s*>$/i,
action: { indentAction: Modes.IndentAction.IndentOutdent }
action: { indentAction: modes.IndentAction.IndentOutdent }
},
{
beforeText: new RegExp(`<(?!(?:${htmlMode.EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
action: { indentAction: Modes.IndentAction.Indent }
action: { indentAction: modes.IndentAction.Indent }
}
],
});
}
public getInitialState() : Modes.IState {
public getInitialState() : modes.IState {
return new HandlebarsState(this, htmlMode.States.Content, States.HTML, '', '', '', '', '');
}
public getLeavingNestedModeData(line:string, state:Modes.IState):ILeavingNestedModeData {
public getLeavingNestedModeData(line:string, state:modes.IState):ILeavingNestedModeData {
var leavingNestedModeData = super.getLeavingNestedModeData(line, state);
if (leavingNestedModeData) {
leavingNestedModeData.stateAfterNestedMode = new HandlebarsState(this, htmlMode.States.Content, States.HTML, '', '', '', '', '');
......
......@@ -19,7 +19,6 @@ import {EMPTY_ELEMENTS} from 'vs/languages/html/common/htmlEmptyTagsShared';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {TokenizationSupport, IEnteringNestedModeData, ILeavingNestedModeData, ITokenizationCustomization} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {CancellationToken} from 'vs/base/common/cancellation';
import {wireCancellationToken} from 'vs/base/common/async';
export { htmlTokenTypes }; // export to be used by Razor. We are the main module, so Razor should get it from us.
......@@ -328,15 +327,30 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode impl
throw new Error('This method must be overwritten!');
}
modes.HoverProviderRegistry.register(this.getId(), this);
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
modes.ReferenceSearchRegistry.register(this.getId(), this);
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: ['.', ':', '<', '"', '=', '/'],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
});
modes.DocumentHighlightProviderRegistry.register(this.getId(), this);
modes.DocumentHighlightProviderRegistry.register(this.getId(), {
provideDocumentHighlights: (model, position, token): Thenable<modes.DocumentHighlight[]> => {
return wireCancellationToken(token, this._provideDocumentHighlights(model.getAssociatedResource(), position));
}
});
modes.FormatRegistry.register(this.getId(), this);
modes.FormatOnTypeRegistry.register(this.getId(), this);
}
......@@ -474,32 +488,23 @@ export class HTMLMode<W extends htmlWorker.HTMLWorker> extends AbstractMode impl
return this._worker((w) => w.format(resource, range, options));
}
public provideHover(model:editorCommon.IReadOnlyModel, position:editorCommon.IEditorPosition, token:CancellationToken): Thenable<modes.Hover> {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
static $_provideHover = OneWorkerAttr(HTMLMode, HTMLMode.prototype._provideHover);
private _provideHover(resource:URI, position:editorCommon.IPosition): winjs.TPromise<modes.Hover> {
protected _provideHover(resource:URI, position:editorCommon.IPosition): winjs.TPromise<modes.Hover> {
return this._worker((w) => w.provideHover(resource, position));
}
static $findReferences = OneWorkerAttr(HTMLMode, HTMLMode.prototype.findReferences);
public findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean): winjs.TPromise<modes.IReference[]> {
public findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean): winjs.TPromise<modes.Location[]> {
return this._worker((w) => w.findReferences(resource, position, includeDeclaration));
}
public provideDocumentHighlights(model: editorCommon.IReadOnlyModel, position: editorCommon.IEditorPosition, token: CancellationToken): Thenable<modes.DocumentHighlight[]> {
return wireCancellationToken(token, this._provideDocumentHighlights(model.getAssociatedResource(), position));
}
static $_provideDocumentHighlights = OneWorkerAttr(HTMLMode, HTMLMode.prototype._provideDocumentHighlights);
private _provideDocumentHighlights(resource:URI, position:editorCommon.IPosition, strict:boolean = false): winjs.TPromise<modes.DocumentHighlight[]> {
protected _provideDocumentHighlights(resource:URI, position:editorCommon.IPosition, strict:boolean = false): winjs.TPromise<modes.DocumentHighlight[]> {
return this._worker((w) => w.provideDocumentHighlights(resource, position, strict));
}
public provideCompletionItems(model:editorCommon.IReadOnlyModel, position:editorCommon.IEditorPosition, token:CancellationToken): Thenable<modes.ISuggestResult[]> {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
static $_provideCompletionItems = OneWorkerAttr(HTMLMode, HTMLMode.prototype._provideCompletionItems);
private _provideCompletionItems(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.ISuggestResult[]> {
protected _provideCompletionItems(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.ISuggestResult[]> {
return this._worker((w) => w.provideCompletionItems(resource, position));
}
......
......@@ -157,7 +157,7 @@ export class HTMLWorker {
});
}
public findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean): winjs.TPromise<modes.IReference[]> {
public findReferences(resource:URI, position:editorCommon.IPosition, includeDeclaration:boolean): winjs.TPromise<modes.Location[]> {
return this._delegateToModeAtPosition(resource, position, (isEmbeddedMode, model) => {
if (isEmbeddedMode) {
return findReferences(model, Position.lift(position));
......
......@@ -5,7 +5,7 @@
'use strict';
import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import modes = require('vs/editor/common/modes');
import URI from 'vs/base/common/uri';
import WinJS = require('vs/base/common/winjs.base');
import Platform = require('vs/platform/platform');
......@@ -17,21 +17,20 @@ import {IThreadService, ThreadAffinity} from 'vs/platform/thread/common/thread';
import {IJSONContributionRegistry, Extensions, ISchemaContributions} from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {CancellationToken} from 'vs/base/common/cancellation';
import {wireCancellationToken} from 'vs/base/common/async';
export class JSONMode extends AbstractMode implements Modes.HoverProvider, Modes.IOutlineSupport {
export class JSONMode extends AbstractMode implements modes.IOutlineSupport {
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
public configSupport:Modes.IConfigurationSupport;
public inplaceReplaceSupport:Modes.IInplaceReplaceSupport;
public tokenizationSupport: modes.ITokenizationSupport;
public richEditSupport: modes.IRichEditSupport;
public configSupport:modes.IConfigurationSupport;
public inplaceReplaceSupport:modes.IInplaceReplaceSupport;
private _modeWorkerManager: ModeWorkerManager<jsonWorker.JSONWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
descriptor:modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService
) {
......@@ -64,20 +63,29 @@ export class JSONMode extends AbstractMode implements Modes.HoverProvider, Modes
}
});
Modes.HoverProviderRegistry.register(this.getId(), this);
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
this.inplaceReplaceSupport = this;
this.configSupport = this;
// Initialize Outline support
Modes.OutlineRegistry.register(this.getId(), this);
modes.OutlineRegistry.register(this.getId(), this);
modes.FormatRegistry.register(this.getId(), this);
Modes.FormatRegistry.register(this.getId(), this);
Modes.FormatOnTypeRegistry.register(this.getId(), this);
modes.FormatOnTypeRegistry.register(this.getId(), this);
Modes.SuggestRegistry.register(this.getId(), {
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: [],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
});
}
......@@ -128,40 +136,32 @@ export class JSONMode extends AbstractMode implements Modes.HoverProvider, Modes
}
static $navigateValueSet = OneWorkerAttr(JSONMode, JSONMode.prototype.navigateValueSet);
public navigateValueSet(resource:URI, position:EditorCommon.IRange, up:boolean):WinJS.TPromise<Modes.IInplaceReplaceSupportResult> {
public navigateValueSet(resource:URI, position:EditorCommon.IRange, up:boolean):WinJS.TPromise<modes.IInplaceReplaceSupportResult> {
return this._worker((w) => w.navigateValueSet(resource, position, up));
}
public provideCompletionItems(model:EditorCommon.IReadOnlyModel, position:EditorCommon.IEditorPosition, token:CancellationToken): Thenable<Modes.ISuggestResult[]> {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
static $_provideCompletionItems = OneWorkerAttr(JSONMode, JSONMode.prototype._provideCompletionItems);
private _provideCompletionItems(resource:URI, position:EditorCommon.IPosition):WinJS.TPromise<Modes.ISuggestResult[]> {
private _provideCompletionItems(resource:URI, position:EditorCommon.IPosition):WinJS.TPromise<modes.ISuggestResult[]> {
return this._worker((w) => w.provideCompletionItems(resource, position));
}
public provideHover(model:EditorCommon.IReadOnlyModel, position:EditorCommon.IEditorPosition, token:CancellationToken): Thenable<Modes.Hover> {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
static $_provideHover = OneWorkerAttr(JSONMode, JSONMode.prototype._provideHover);
private _provideHover(resource:URI, position:EditorCommon.IPosition): WinJS.TPromise<Modes.Hover> {
private _provideHover(resource:URI, position:EditorCommon.IPosition): WinJS.TPromise<modes.Hover> {
return this._worker((w) => w.provideHover(resource, position));
}
static $getOutline = OneWorkerAttr(JSONMode, JSONMode.prototype.getOutline);
public getOutline(resource:URI):WinJS.TPromise<Modes.IOutlineEntry[]> {
public getOutline(resource:URI):WinJS.TPromise<modes.IOutlineEntry[]> {
return this._worker((w) => w.getOutline(resource));
}
static $formatDocument = OneWorkerAttr(JSONMode, JSONMode.prototype.formatDocument);
public formatDocument(resource:URI, options:Modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
public formatDocument(resource:URI, options:modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
return this._worker((w) => w.format(resource, null, options));
}
static $formatRange = OneWorkerAttr(JSONMode, JSONMode.prototype.formatRange);
public formatRange(resource:URI, range:EditorCommon.IRange, options:Modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
public formatRange(resource:URI, range:EditorCommon.IRange, options:modes.IFormattingOptions):WinJS.TPromise<EditorCommon.ISingleEditOperation[]> {
return this._worker((w) => w.format(resource, range, options));
}
}
\ No newline at end of file
......@@ -6,8 +6,8 @@
import winjs = require('vs/base/common/winjs.base');
import URI from 'vs/base/common/uri';
import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import editorCommon = require('vs/editor/common/editorCommon');
import modes = require('vs/editor/common/modes');
import Types = require('vs/editor/common/modes/monarch/monarchTypes');
import Compile = require('vs/editor/common/modes/monarch/monarchCompile');
import lessWorker = require('vs/languages/less/common/lessWorker');
......@@ -19,7 +19,6 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import {IThreadService, ThreadAffinity} from 'vs/platform/thread/common/thread';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
import {CancellationToken} from 'vs/base/common/cancellation';
import {wireCancellationToken} from 'vs/base/common/async';
import {createRichEditSupport} from 'vs/editor/common/modes/monarch/monarchDefinition';
import {createTokenizationSupport} from 'vs/editor/common/modes/monarch/monarchLexer';
......@@ -177,19 +176,19 @@ export var language: Types.ILanguage = <Types.ILanguage> {
}
};
export class LESSMode extends AbstractMode implements Modes.HoverProvider, Modes.IOutlineSupport {
export class LESSMode extends AbstractMode implements modes.IOutlineSupport {
public inplaceReplaceSupport:Modes.IInplaceReplaceSupport;
public configSupport:Modes.IConfigurationSupport;
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
public inplaceReplaceSupport:modes.IInplaceReplaceSupport;
public configSupport:modes.IConfigurationSupport;
public tokenizationSupport: modes.ITokenizationSupport;
public richEditSupport: modes.IRichEditSupport;
private modeService: IModeService;
private _modeWorkerManager: ModeWorkerManager<lessWorker.LessWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
descriptor:modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService,
......@@ -204,19 +203,32 @@ export class LESSMode extends AbstractMode implements Modes.HoverProvider, Modes
this.modeService = modeService;
Modes.HoverProviderRegistry.register(this.getId(), this);
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
this.inplaceReplaceSupport = this;
this.configSupport = this;
Modes.ReferenceSearchRegistry.register(this.getId(), this);
Modes.DeclarationRegistry.register(this.getId(), {
findDeclaration: (resource, position) => this.findDeclaration(resource, position)
modes.ReferenceSearchRegistry.register(this.getId(), this);
modes.DefinitionProviderRegistry.register(this.getId(), {
provideDefinition: (model, position, token): Thenable<modes.Definition> => {
return wireCancellationToken(token, this._provideDefinition(model.getAssociatedResource(), position));
}
});
Modes.OutlineRegistry.register(this.getId(), this);
Modes.SuggestRegistry.register(this.getId(), {
modes.OutlineRegistry.register(this.getId(), this);
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: [],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
});
this.tokenizationSupport = createTokenizationSupport(modeService, this, lexer);
......@@ -249,7 +261,7 @@ export class LESSMode extends AbstractMode implements Modes.HoverProvider, Modes
}
static $navigateValueSet = OneWorkerAttr(LESSMode, LESSMode.prototype.navigateValueSet);
public navigateValueSet(resource:URI, position:EditorCommon.IRange, up:boolean):winjs.TPromise<Modes.IInplaceReplaceSupportResult> {
public navigateValueSet(resource:URI, position:editorCommon.IRange, up:boolean):winjs.TPromise<modes.IInplaceReplaceSupportResult> {
return this._worker((w) => w.navigateValueSet(resource, position, up));
}
......@@ -259,40 +271,32 @@ export class LESSMode extends AbstractMode implements Modes.HoverProvider, Modes
}
static $findReferences = OneWorkerAttr(LESSMode, LESSMode.prototype.findReferences);
public findReferences(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.IReference[]> {
public findReferences(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.Location[]> {
return this._worker((w) => w.findReferences(resource, position));
}
public provideCompletionItems(model:EditorCommon.IReadOnlyModel, position:EditorCommon.IEditorPosition, token:CancellationToken): Thenable<Modes.ISuggestResult[]> {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
static $_provideCompletionItems = OneWorkerAttr(LESSMode, LESSMode.prototype._provideCompletionItems);
private _provideCompletionItems(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.ISuggestResult[]> {
private _provideCompletionItems(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.ISuggestResult[]> {
return this._worker((w) => w.provideCompletionItems(resource, position));
}
public provideHover(model:EditorCommon.IReadOnlyModel, position:EditorCommon.IEditorPosition, token:CancellationToken): Thenable<Modes.Hover> {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
static $_provideHover = OneWorkerAttr(LESSMode, LESSMode.prototype._provideHover);
private _provideHover(resource:URI, position:EditorCommon.IPosition): winjs.TPromise<Modes.Hover> {
private _provideHover(resource:URI, position:editorCommon.IPosition): winjs.TPromise<modes.Hover> {
return this._worker((w) => w.provideHover(resource, position));
}
static $getOutline = OneWorkerAttr(LESSMode, LESSMode.prototype.getOutline);
public getOutline(resource:URI):winjs.TPromise<Modes.IOutlineEntry[]> {
public getOutline(resource:URI):winjs.TPromise<modes.IOutlineEntry[]> {
return this._worker((w) => w.getOutline(resource));
}
static $findDeclaration = OneWorkerAttr(LESSMode, LESSMode.prototype.findDeclaration);
public findDeclaration(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.IReference> {
return this._worker((w) => w.findDeclaration(resource, position));
static $_provideDefinition = OneWorkerAttr(LESSMode, LESSMode.prototype._provideDefinition);
private _provideDefinition(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.Definition> {
return this._worker((w) => w.provideDefinition(resource, position));
}
static $findColorDeclarations = OneWorkerAttr(LESSMode, LESSMode.prototype.findColorDeclarations);
public findColorDeclarations(resource:URI):winjs.TPromise<{range:EditorCommon.IRange; value:string; }[]> {
public findColorDeclarations(resource:URI):winjs.TPromise<{range:editorCommon.IRange; value:string; }[]> {
return this._worker((w) => w.findColorDeclarations(resource));
}
}
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import Modes = require('vs/editor/common/modes');
import modes = require('vs/editor/common/modes');
import htmlMode = require('vs/languages/html/common/html');
import csharpTokenization = require('vs/languages/razor/common/csharpTokenization');
import {createWordRegExp, ModeWorkerManager} from 'vs/editor/common/modes/abstractMode';
......@@ -15,12 +15,13 @@ import {IModeService} from 'vs/editor/common/services/modeService';
import {RichEditSupport} from 'vs/editor/common/modes/supports/richEditSupport';
import {ILeavingNestedModeData} from 'vs/editor/common/modes/supports/tokenizationSupport';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {wireCancellationToken} from 'vs/base/common/async';
// for a brief description of the razor syntax see http://www.mikesdotnetting.com/Article/153/Inline-Razor-Syntax-Overview
class RAZORState extends htmlMode.State {
constructor(mode:Modes.IMode, kind:htmlMode.States, lastTagName:string, lastAttributeName:string, embeddedContentType:string, attributeValueQuote:string, attributeValue:string) {
constructor(mode:modes.IMode, kind:htmlMode.States, lastTagName:string, lastAttributeName:string, embeddedContentType:string, attributeValueQuote:string, attributeValue:string) {
super(mode, kind, lastTagName, lastAttributeName, embeddedContentType, attributeValueQuote, attributeValue);
}
......@@ -28,7 +29,7 @@ class RAZORState extends htmlMode.State {
return new RAZORState(this.getMode(), this.kind, this.lastTagName, this.lastAttributeName, this.embeddedContentType, this.attributeValueQuote, this.attributeValue);
}
public equals(other:Modes.IState):boolean {
public equals(other:modes.IState):boolean {
if (other instanceof RAZORState) {
return (
super.equals(other)
......@@ -37,7 +38,7 @@ class RAZORState extends htmlMode.State {
return false;
}
public tokenize(stream:Modes.IStream):Modes.ITokenizationResult {
public tokenize(stream:modes.IStream):modes.ITokenizationResult {
if (!stream.eos() && stream.peek() === '@') {
stream.next();
......@@ -56,7 +57,7 @@ class RAZORState extends htmlMode.State {
export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
constructor(
descriptor:Modes.IModeDescriptor,
descriptor:modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IModeService modeService: IModeService,
@IThreadService threadService: IThreadService
......@@ -65,21 +66,34 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
}
protected _registerSupports(): void {
Modes.HoverProviderRegistry.register(this.getId(), this);
Modes.ReferenceSearchRegistry.register(this.getId(), this);
Modes.SuggestRegistry.register(this.getId(), {
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
modes.ReferenceSearchRegistry.register(this.getId(), this);
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: ['.', ':', '<', '"', '=', '/'],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
});
modes.DocumentHighlightProviderRegistry.register(this.getId(), {
provideDocumentHighlights: (model, position, token): Thenable<modes.DocumentHighlight[]> => {
return wireCancellationToken(token, this._provideDocumentHighlights(model.getAssociatedResource(), position));
}
});
Modes.DocumentHighlightProviderRegistry.register(this.getId(), this);
}
protected _createModeWorkerManager(descriptor:Modes.IModeDescriptor, instantiationService: IInstantiationService): ModeWorkerManager<RAZORWorker> {
protected _createModeWorkerManager(descriptor:modes.IModeDescriptor, instantiationService: IInstantiationService): ModeWorkerManager<RAZORWorker> {
return new ModeWorkerManager<RAZORWorker>(descriptor, 'vs/languages/razor/common/razorWorker', 'RAZORWorker', 'vs/languages/html/common/htmlWorker', instantiationService);
}
protected _createRichEditSupport(): Modes.IRichEditSupport {
protected _createRichEditSupport(): modes.IRichEditSupport {
return new RichEditSupport(this.getId(), null, {
wordPattern: createWordRegExp('#?%'),
......@@ -117,21 +131,21 @@ export class RAZORMode extends htmlMode.HTMLMode<RAZORWorker> {
{
beforeText: new RegExp(`<(?!(?:${htmlMode.EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
afterText: /^<\/(\w[\w\d]*)\s*>$/i,
action: { indentAction: Modes.IndentAction.IndentOutdent }
action: { indentAction: modes.IndentAction.IndentOutdent }
},
{
beforeText: new RegExp(`<(?!(?:${htmlMode.EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
action: { indentAction: Modes.IndentAction.Indent }
action: { indentAction: modes.IndentAction.Indent }
}
],
});
}
public getInitialState(): Modes.IState {
public getInitialState(): modes.IState {
return new RAZORState(this, htmlMode.States.Content, '', '', '', '', '');
}
public getLeavingNestedModeData(line:string, state:Modes.IState): ILeavingNestedModeData {
public getLeavingNestedModeData(line:string, state:modes.IState): ILeavingNestedModeData {
var leavingNestedModeData = super.getLeavingNestedModeData(line, state);
if (leavingNestedModeData) {
leavingNestedModeData.stateAfterNestedMode = new RAZORState(this, htmlMode.States.Content, '', '', '', '', '');
......
......@@ -8,8 +8,8 @@ import Types = require('vs/editor/common/modes/monarch/monarchTypes');
import Compile = require('vs/editor/common/modes/monarch/monarchCompile');
import winjs = require('vs/base/common/winjs.base');
import URI from 'vs/base/common/uri';
import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import editorCommon = require('vs/editor/common/editorCommon');
import modes = require('vs/editor/common/modes');
import sassWorker = require('vs/languages/sass/common/sassWorker');
import * as sassTokenTypes from 'vs/languages/sass/common/sassTokenTypes';
import {ModeWorkerManager, AbstractMode} from 'vs/editor/common/modes/abstractMode';
......@@ -19,7 +19,6 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
import {IThreadService, ThreadAffinity} from 'vs/platform/thread/common/thread';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
import {CancellationToken} from 'vs/base/common/cancellation';
import {wireCancellationToken} from 'vs/base/common/async';
import {createRichEditSupport} from 'vs/editor/common/modes/monarch/monarchDefinition';
import {createTokenizationSupport} from 'vs/editor/common/modes/monarch/monarchLexer';
......@@ -279,19 +278,19 @@ export var language = <Types.ILanguage>{
}
};
export class SASSMode extends AbstractMode implements Modes.HoverProvider, Modes.IOutlineSupport {
export class SASSMode extends AbstractMode implements modes.IOutlineSupport {
public inplaceReplaceSupport:Modes.IInplaceReplaceSupport;
public configSupport:Modes.IConfigurationSupport;
public tokenizationSupport: Modes.ITokenizationSupport;
public richEditSupport: Modes.IRichEditSupport;
public inplaceReplaceSupport:modes.IInplaceReplaceSupport;
public configSupport:modes.IConfigurationSupport;
public tokenizationSupport: modes.ITokenizationSupport;
public richEditSupport: modes.IRichEditSupport;
private modeService: IModeService;
private _modeWorkerManager: ModeWorkerManager<sassWorker.SassWorker>;
private _threadService:IThreadService;
constructor(
descriptor:Modes.IModeDescriptor,
descriptor:modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@IModeService modeService: IModeService,
......@@ -305,20 +304,32 @@ export class SASSMode extends AbstractMode implements Modes.HoverProvider, Modes
this.modeService = modeService;
Modes.HoverProviderRegistry.register(this.getId(), this);
modes.HoverProviderRegistry.register(this.getId(), {
provideHover: (model, position, token): Thenable<modes.Hover> => {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
});
this.inplaceReplaceSupport = this;
this.configSupport = this;
Modes.ReferenceSearchRegistry.register(this.getId(), this);
Modes.DeclarationRegistry.register(this.getId(), {
findDeclaration: (resource, position) => this.findDeclaration(resource, position)
modes.ReferenceSearchRegistry.register(this.getId(), this);
modes.DefinitionProviderRegistry.register(this.getId(), {
provideDefinition: (model, position, token): Thenable<modes.Definition> => {
return wireCancellationToken(token, this._provideDefinition(model.getAssociatedResource(), position));
}
});
Modes.OutlineRegistry.register(this.getId(), this);
Modes.SuggestRegistry.register(this.getId(), {
modes.OutlineRegistry.register(this.getId(), this);
modes.SuggestRegistry.register(this.getId(), {
triggerCharacters: [],
shouldAutotriggerSuggest: true,
provideCompletionItems: (model, position, token) => this.provideCompletionItems(model, position, token)
});
provideCompletionItems: (model, position, token): Thenable<modes.ISuggestResult[]> => {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
} });
this.tokenizationSupport = createTokenizationSupport(modeService, this, lexer);
......@@ -350,7 +361,7 @@ export class SASSMode extends AbstractMode implements Modes.HoverProvider, Modes
}
static $navigateValueSet = OneWorkerAttr(SASSMode, SASSMode.prototype.navigateValueSet);
public navigateValueSet(resource:URI, position:EditorCommon.IRange, up:boolean):winjs.TPromise<Modes.IInplaceReplaceSupportResult> {
public navigateValueSet(resource:URI, position:editorCommon.IRange, up:boolean):winjs.TPromise<modes.IInplaceReplaceSupportResult> {
return this._worker((w) => w.navigateValueSet(resource, position, up));
}
......@@ -360,40 +371,32 @@ export class SASSMode extends AbstractMode implements Modes.HoverProvider, Modes
}
static $findReferences = OneWorkerAttr(SASSMode, SASSMode.prototype.findReferences);
public findReferences(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.IReference[]> {
public findReferences(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.Location[]> {
return this._worker((w) => w.findReferences(resource, position));
}
public provideCompletionItems(model:EditorCommon.IReadOnlyModel, position:EditorCommon.IEditorPosition, token:CancellationToken): Thenable<Modes.ISuggestResult[]> {
return wireCancellationToken(token, this._provideCompletionItems(model.getAssociatedResource(), position));
}
static $_provideCompletionItems = OneWorkerAttr(SASSMode, SASSMode.prototype._provideCompletionItems);
private _provideCompletionItems(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.ISuggestResult[]> {
private _provideCompletionItems(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.ISuggestResult[]> {
return this._worker((w) => w.provideCompletionItems(resource, position));
}
public provideHover(model:EditorCommon.IReadOnlyModel, position:EditorCommon.IEditorPosition, token:CancellationToken): Thenable<Modes.Hover> {
return wireCancellationToken(token, this._provideHover(model.getAssociatedResource(), position));
}
static $_provideHover = OneWorkerAttr(SASSMode, SASSMode.prototype._provideHover);
private _provideHover(resource:URI, position:EditorCommon.IPosition): winjs.TPromise<Modes.Hover> {
private _provideHover(resource:URI, position:editorCommon.IPosition): winjs.TPromise<modes.Hover> {
return this._worker((w) => w.provideHover(resource, position));
}
static $getOutline = OneWorkerAttr(SASSMode, SASSMode.prototype.getOutline);
public getOutline(resource:URI):winjs.TPromise<Modes.IOutlineEntry[]> {
public getOutline(resource:URI):winjs.TPromise<modes.IOutlineEntry[]> {
return this._worker((w) => w.getOutline(resource));
}
static $findDeclaration = OneWorkerAttr(SASSMode, SASSMode.prototype.findDeclaration);
public findDeclaration(resource:URI, position:EditorCommon.IPosition):winjs.TPromise<Modes.IReference> {
return this._worker((w) => w.findDeclaration(resource, position));
static $_provideDefinition = OneWorkerAttr(SASSMode, SASSMode.prototype._provideDefinition);
private _provideDefinition(resource:URI, position:editorCommon.IPosition):winjs.TPromise<modes.Definition> {
return this._worker((w) => w.provideDefinition(resource, position));
}
static $findColorDeclarations = OneWorkerAttr(SASSMode, SASSMode.prototype.findColorDeclarations);
public findColorDeclarations(resource:URI):winjs.TPromise<{range:EditorCommon.IRange; value:string; }[]> {
public findColorDeclarations(resource:URI):winjs.TPromise<{range:editorCommon.IRange; value:string; }[]> {
return this._worker((w) => w.findColorDeclarations(resource));
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ export function register(modelService: IModelService, markerService: IMarkerServ
disposables.push(modes.SignatureHelpProviderRegistry.register(selector, new SignatureHelpAdapter(modelService, worker)));
disposables.push(modes.HoverProviderRegistry.register(selector, new QuickInfoAdapter(modelService, worker)));
disposables.push(modes.DocumentHighlightProviderRegistry.register(selector, new OccurrencesAdapter(modelService, worker)));
disposables.push(modes.DeclarationRegistry.register(selector, new DeclarationAdapter(modelService, worker)));
disposables.push(modes.DefinitionProviderRegistry.register(selector, new DefinitionAdapter(modelService, worker)));
disposables.push(modes.ReferenceSearchRegistry.register(selector, new ReferenceAdapter(modelService, worker)));
disposables.push(modes.OutlineRegistry.register(selector, new OutlineAdapter(modelService, worker)));
disposables.push(modes.FormatRegistry.register(selector, new FormatAdapter(modelService, worker)));
......@@ -338,27 +338,29 @@ class OccurrencesAdapter extends Adapter implements modes.DocumentHighlightProvi
// --- definition ------
class DeclarationAdapter extends Adapter implements modes.IDeclarationSupport {
class DefinitionAdapter extends Adapter {
findDeclaration(resource: URI, position: editorCommon.IPosition): TPromise<modes.IReference[]> {
return this._worker(resource).then(worker => {
public provideDefinition(model:editorCommon.IReadOnlyModel, position:editorCommon.IEditorPosition, token:CancellationToken): Thenable<modes.Definition> {
const resource = model.getAssociatedResource();
return wireCancellationToken(token, this._worker(resource).then(worker => {
return worker.getDefinitionAtPosition(resource.toString(), this._positionToOffset(resource, position));
}).then(entries => {
if (!entries) {
return;
}
const result: modes.IReference[] = [];
const result: modes.Location[] = [];
for (let entry of entries) {
const uri = URI.parse(entry.fileName);
if (this._modelService.getModel(uri)) {
result.push({
resource: uri,
uri: uri,
range: this._textSpanToRange(uri, entry.textSpan)
});
}
}
return result;
});
}));
}
}
......@@ -366,19 +368,19 @@ class DeclarationAdapter extends Adapter implements modes.IDeclarationSupport {
class ReferenceAdapter extends Adapter implements modes.IReferenceSupport {
findReferences(resource: URI, position: editorCommon.IPosition, includeDeclaration: boolean): TPromise<modes.IReference[]> {
findReferences(resource: URI, position: editorCommon.IPosition, includeDeclaration: boolean): TPromise<modes.Location[]> {
return this._worker(resource).then(worker => {
return worker.getReferencesAtPosition(resource.toString(), this._positionToOffset(resource, position));
}).then(entries => {
if (!entries) {
return;
}
const result: modes.IReference[] = [];
const result: modes.Location[] = [];
for (let entry of entries) {
const uri = URI.parse(entry.fileName);
if (this._modelService.getModel(uri)) {
result.push({
resource: uri,
uri: uri,
range: this._textSpanToRange(uri, entry.textSpan)
});
}
......
......@@ -236,7 +236,7 @@ class ExtHostApiCommands {
resource,
position: position && typeConverters.fromPosition(position)
};
return this._commands.executeCommand<modes.IReference[]>('_executeDefinitionProvider', args).then(value => {
return this._commands.executeCommand<modes.Location[]>('_executeDefinitionProvider', args).then(value => {
if (Array.isArray(value)) {
return value.map(typeConverters.location.to);
}
......@@ -272,7 +272,7 @@ class ExtHostApiCommands {
resource,
position: position && typeConverters.fromPosition(position)
};
return this._commands.executeCommand<modes.IReference[]>('_executeReferenceProvider', args).then(value => {
return this._commands.executeCommand<modes.Location[]>('_executeReferenceProvider', args).then(value => {
if (Array.isArray(value)) {
return value.map(typeConverters.location.to);
}
......
......@@ -152,7 +152,7 @@ class CodeLensAdapter implements modes.ICodeLensSupport {
}
}
class DeclarationAdapter implements modes.IDeclarationSupport {
class DefinitionAdapter {
private _documents: ExtHostModelService;
private _provider: vscode.DefinitionProvider;
......@@ -162,24 +162,24 @@ class DeclarationAdapter implements modes.IDeclarationSupport {
this._provider = provider;
}
findDeclaration(resource: URI, position: IPosition): TPromise<modes.IReference[]> {
provideDefinition(resource: URI, position: IPosition): TPromise<modes.Definition> {
let doc = this._documents.getDocumentData(resource).document;
let pos = TypeConverters.toPosition(position);
return asWinJsPromise(token => this._provider.provideDefinition(doc, pos, token)).then(value => {
if (Array.isArray(value)) {
return value.map(DeclarationAdapter._convertLocation);
return value.map(DefinitionAdapter._convertLocation);
} else if (value) {
return DeclarationAdapter._convertLocation(value);
return DefinitionAdapter._convertLocation(value);
}
});
}
private static _convertLocation(location: vscode.Location): modes.IReference {
private static _convertLocation(location: vscode.Location): modes.Location {
if (!location) {
return;
}
return <modes.IReference>{
resource: location.uri,
return <modes.Location>{
uri: location.uri,
range: TypeConverters.fromRange(location.range)
};
}
......@@ -256,7 +256,7 @@ class ReferenceAdapter implements modes.IReferenceSupport {
this._provider = provider;
}
findReferences(resource: URI, position: IPosition, includeDeclaration: boolean): TPromise<modes.IReference[]> {
findReferences(resource: URI, position: IPosition, includeDeclaration: boolean): TPromise<modes.Location[]> {
let doc = this._documents.getDocumentData(resource).document;
let pos = TypeConverters.toPosition(position);
......@@ -267,9 +267,9 @@ class ReferenceAdapter implements modes.IReferenceSupport {
});
}
private static _convertLocation(location: vscode.Location): modes.IReference {
return <modes.IReference>{
resource: location.uri,
private static _convertLocation(location: vscode.Location): modes.Location {
return <modes.Location>{
uri: location.uri,
range: TypeConverters.fromRange(location.range)
};
}
......@@ -594,7 +594,7 @@ class SignatureHelpAdapter {
}
}
type Adapter = OutlineAdapter | CodeLensAdapter | DeclarationAdapter | HoverAdapter
type Adapter = OutlineAdapter | CodeLensAdapter | DefinitionAdapter | HoverAdapter
| DocumentHighlightAdapter | ReferenceAdapter | QuickFixAdapter | DocumentFormattingAdapter
| RangeFormattingAdapter | OnTypeFormattingAdapter | NavigateTypeAdapter | RenameAdapter
| SuggestAdapter | SignatureHelpAdapter;
......@@ -670,13 +670,13 @@ export class ExtHostLanguageFeatures {
registerDefinitionProvider(selector: vscode.DocumentSelector, provider: vscode.DefinitionProvider): vscode.Disposable {
const handle = this._nextHandle();
this._adapter[handle] = new DeclarationAdapter(this._documents, provider);
this._adapter[handle] = new DefinitionAdapter(this._documents, provider);
this._proxy.$registerDeclaractionSupport(handle, selector);
return this._createDisposable(handle);
}
$findDeclaration(handle: number, resource: URI, position: IPosition): TPromise<modes.IReference[]> {
return this._withAdapter(handle, DeclarationAdapter, adapter => adapter.findDeclaration(resource, position));
$provideDefinition(handle: number, resource: URI, position: IPosition): TPromise<modes.Definition> {
return this._withAdapter(handle, DefinitionAdapter, adapter => adapter.provideDefinition(resource, position));
}
// --- extra info
......@@ -714,7 +714,7 @@ export class ExtHostLanguageFeatures {
return this._createDisposable(handle);
}
$findReferences(handle: number, resource: URI, position: IPosition, includeDeclaration: boolean): TPromise<modes.IReference[]> {
$findReferences(handle: number, resource: URI, position: IPosition, includeDeclaration: boolean): TPromise<modes.Location[]> {
return this._withAdapter(handle, ReferenceAdapter, adapter => adapter.findReferences(resource, position, includeDeclaration));
}
......@@ -874,9 +874,9 @@ export class MainThreadLanguageFeatures {
// --- declaration
$registerDeclaractionSupport(handle: number, selector: vscode.DocumentSelector): TPromise<any> {
this._registrations[handle] = modes.DeclarationRegistry.register(selector, <modes.IDeclarationSupport>{
findDeclaration: (resource: URI, position: IPosition): TPromise<modes.IReference[]> => {
return this._proxy.$findDeclaration(handle, resource, position);
this._registrations[handle] = modes.DefinitionProviderRegistry.register(selector, <modes.DefinitionProvider>{
provideDefinition: (model, position, token): Thenable<modes.Definition> => {
return wireCancellationToken(token, this._proxy.$provideDefinition(handle, model.getAssociatedResource(), position));
}
});
return undefined;
......@@ -908,7 +908,7 @@ export class MainThreadLanguageFeatures {
$registerReferenceSupport(handle: number, selector: vscode.DocumentSelector): TPromise<any> {
this._registrations[handle] = modes.ReferenceSearchRegistry.register(selector, <modes.IReferenceSupport>{
findReferences: (resource: URI, position: IPosition, includeDeclaration: boolean): TPromise<modes.IReference[]> => {
findReferences: (resource: URI, position: IPosition, includeDeclaration: boolean): TPromise<modes.Location[]> => {
return this._proxy.$findReferences(handle, resource, position, includeDeclaration);
}
});
......
......@@ -327,14 +327,14 @@ export function toSymbolInformation(bearing: ITypeBearing): types.SymbolInformat
export const location = {
from(value: types.Location): modes.IReference {
from(value: types.Location): modes.Location {
return {
range: fromRange(value.range),
resource: value.uri
uri: value.uri
};
},
to(value: modes.IReference): types.Location {
return new types.Location(value.resource, toRange(value.range));
to(value: modes.Location): types.Location {
return new types.Location(value.uri, toRange(value.range));
}
};
......
......@@ -243,11 +243,11 @@ suite('ExtHostLanguageFeatures', function() {
return threadService.sync().then(() => {
return getDeclarationsAtPosition(model, { lineNumber: 1, column: 1 }).then(value => {
return getDeclarationsAtPosition(model, new EditorPosition(1, 1)).then(value => {
assert.equal(value.length, 1);
let [entry] = value;
assert.deepEqual(entry.range, { startLineNumber: 2, startColumn: 3, endLineNumber: 4, endColumn: 5 });
assert.equal(entry.resource.toString(), model.getAssociatedResource().toString());
assert.equal(entry.uri.toString(), model.getAssociatedResource().toString());
});
});
});
......@@ -267,7 +267,7 @@ suite('ExtHostLanguageFeatures', function() {
return threadService.sync().then(() => {
return getDeclarationsAtPosition(model, { lineNumber: 1, column: 1 }).then(value => {
return getDeclarationsAtPosition(model, new EditorPosition(1, 1)).then(value => {
assert.equal(value.length, 2);
});
});
......@@ -289,12 +289,12 @@ suite('ExtHostLanguageFeatures', function() {
return threadService.sync().then(() => {
return getDeclarationsAtPosition(model, { lineNumber: 1, column: 1 }).then(value => {
return getDeclarationsAtPosition(model, new EditorPosition(1, 1)).then(value => {
assert.equal(value.length, 2);
// let [first, second] = value;
assert.equal(value[0].resource.authority, 'second');
assert.equal(value[1].resource.authority, 'first');
assert.equal(value[0].uri.authority, 'second');
assert.equal(value[1].uri.authority, 'first');
});
});
});
......@@ -314,7 +314,7 @@ suite('ExtHostLanguageFeatures', function() {
return threadService.sync().then(() => {
return getDeclarationsAtPosition(model, { lineNumber: 1, column: 1 }).then(value => {
return getDeclarationsAtPosition(model, new EditorPosition(1, 1)).then(value => {
assert.equal(value.length, 1);
});
});
......@@ -519,8 +519,8 @@ suite('ExtHostLanguageFeatures', function() {
assert.equal(value.length, 2);
let [first, second] = value;
assert.equal(first.resource.path, '/second');
assert.equal(second.resource.path, '/first');
assert.equal(first.uri.path, '/second');
assert.equal(second.uri.path, '/first');
});
});
});
......@@ -540,7 +540,7 @@ suite('ExtHostLanguageFeatures', function() {
let [item] = value;
assert.deepEqual(item.range, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 });
assert.equal(item.resource.toString(), model.getAssociatedResource().toString());
assert.equal(item.uri.toString(), model.getAssociatedResource().toString());
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册