mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-27 02:37:26 +01:00
Add location converter
This commit is contained in:
@@ -35,7 +35,7 @@ export default class TypeScriptDefinitionProviderBase {
|
||||
return locations.map(location => {
|
||||
const resource = this.client.asUrl(location.file);
|
||||
return resource
|
||||
? new Location(resource, typeConverters.Range.fromTextSpan(location))
|
||||
? typeConverters.Location.fromTextSpan(resource, location)
|
||||
: undefined;
|
||||
}).filter(x => x) as Location[];
|
||||
} catch {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DocumentSymbolProvider, SymbolInformation, SymbolKind, TextDocument, Location, CancellationToken, Uri } from 'vscode';
|
||||
import { DocumentSymbolProvider, SymbolInformation, SymbolKind, TextDocument, CancellationToken, Uri } from 'vscode';
|
||||
|
||||
import * as Proto from '../protocol';
|
||||
import * as PConst from '../protocol.const';
|
||||
@@ -71,7 +71,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
|
||||
let result = new SymbolInformation(item.text,
|
||||
outlineTypeTable[item.kind as string] || SymbolKind.Variable,
|
||||
containerLabel ? containerLabel : '',
|
||||
new Location(resource, typeConverters.Range.fromTextSpan(item.spans[0])));
|
||||
typeConverters.Location.fromTextSpan(resource, item.spans[0]));
|
||||
foldingMap[key] = result;
|
||||
bucket.push(result);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
|
||||
const result = new SymbolInformation(item.text,
|
||||
outlineTypeTable[item.kind as string] || SymbolKind.Variable,
|
||||
containerLabel ? containerLabel : '',
|
||||
new Location(resource, typeConverters.Range.fromTextSpan(item.spans[0]))
|
||||
typeConverters.Location.fromTextSpan(resource, item.spans[0])
|
||||
);
|
||||
if (item.childItems && item.childItems.length > 0) {
|
||||
for (const child of item.childItems) {
|
||||
|
||||
@@ -36,7 +36,7 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider {
|
||||
continue;
|
||||
}
|
||||
const url = this.client.asUrl(ref.file);
|
||||
const location = new Location(url, typeConverters.Range.fromTextSpan(ref));
|
||||
const location = typeConverters.Location.fromTextSpan(url, ref);
|
||||
result.push(location);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CodeLens, CancellationToken, TextDocument, Range, Location, workspace } from 'vscode';
|
||||
import { CodeLens, CancellationToken, TextDocument, Range, workspace } from 'vscode';
|
||||
import * as Proto from '../protocol';
|
||||
import * as PConst from '../protocol.const';
|
||||
|
||||
@@ -45,7 +45,7 @@ export default class TypeScriptReferencesCodeLensProvider extends TypeScriptBase
|
||||
|
||||
const locations = response.body.refs
|
||||
.map(reference =>
|
||||
new Location(this.client.asUrl(reference.file), typeConverters.Range.fromTextSpan(reference)))
|
||||
typeConverters.Location.fromTextSpan(this.client.asUrl(reference.file), reference))
|
||||
.filter(location =>
|
||||
// Exclude original definition from references
|
||||
!(location.uri.toString() === codeLens.document.toString() &&
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Location, CancellationToken } from 'vscode';
|
||||
import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, CancellationToken } from 'vscode';
|
||||
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
@@ -71,10 +71,9 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
|
||||
if (!item.containerName && item.kind === 'alias') {
|
||||
continue;
|
||||
}
|
||||
const range = typeConverters.Range.fromTextSpan(item);
|
||||
const label = TypeScriptWorkspaceSymbolProvider.getLabel(item);
|
||||
result.push(new SymbolInformation(label, getSymbolKind(item), item.containerName || '',
|
||||
new Location(this.client.asUrl(item.file), range)));
|
||||
typeConverters.Location.fromTextSpan(this.client.asUrl(item.file), item)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ export namespace Position {
|
||||
});
|
||||
}
|
||||
|
||||
export namespace Location {
|
||||
export const fromTextSpan = (resource: vscode.Uri, tsTextSpan: Proto.TextSpan): vscode.Location =>
|
||||
new vscode.Location(resource, Range.fromTextSpan(tsTextSpan));
|
||||
}
|
||||
|
||||
export namespace TextEdit {
|
||||
export const fromCodeEdit = (edit: Proto.CodeEdit): vscode.TextEdit =>
|
||||
new vscode.TextEdit(
|
||||
|
||||
Reference in New Issue
Block a user