mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-13 15:35:20 +01:00
Small cleanup to ts extension
This commit is contained in:
@@ -140,14 +140,12 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||
private client: ITypescriptServiceClient,
|
||||
private typingsStatus: TypingsStatus
|
||||
) {
|
||||
this.client = client;
|
||||
this.typingsStatus = typingsStatus;
|
||||
this.config = { useCodeSnippetsOnMethodSuggest: false };
|
||||
}
|
||||
|
||||
public updateConfiguration(): void {
|
||||
// Use shared setting for js and ts
|
||||
let typeScriptConfig = workspace.getConfiguration('typescript');
|
||||
const typeScriptConfig = workspace.getConfiguration('typescript');
|
||||
this.config.useCodeSnippetsOnMethodSuggest = typeScriptConfig.get(Configuration.useCodeSnippetsOnMethodSuggest, false);
|
||||
}
|
||||
|
||||
@@ -203,8 +201,8 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||
}
|
||||
|
||||
for (let i = 0; i < body.length; i++) {
|
||||
let element = body[i];
|
||||
let item = new MyCompletionItem(position, document, element, enableDotCompletions);
|
||||
const element = body[i];
|
||||
const item = new MyCompletionItem(position, document, element, enableDotCompletions);
|
||||
completionItems.push(item);
|
||||
}
|
||||
}
|
||||
@@ -225,7 +223,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||
if (!filepath) {
|
||||
return null;
|
||||
}
|
||||
let args: CompletionDetailsRequestArgs = {
|
||||
const args: CompletionDetailsRequestArgs = {
|
||||
file: filepath,
|
||||
line: item.position.line + 1,
|
||||
offset: item.position.character + 1,
|
||||
|
||||
@@ -11,35 +11,26 @@ import * as Proto from '../protocol';
|
||||
import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
export default class TypeScriptDefinitionProviderBase {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
|
||||
public tokens: string[] = [];
|
||||
|
||||
constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
}
|
||||
constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
protected getSymbolLocations(definitionType: 'definition' | 'implementation', document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Location[] | null> {
|
||||
const filepath = this.client.normalizePath(document.uri);
|
||||
if (!filepath) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let args: Proto.FileLocationRequestArgs = {
|
||||
const args: Proto.FileLocationRequestArgs = {
|
||||
file: filepath,
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return this.client.execute(definitionType, args, token).then(response => {
|
||||
let locations: Proto.FileSpan[] = (response && response.body) || [];
|
||||
const locations: Proto.FileSpan[] = (response && response.body) || [];
|
||||
if (!locations || locations.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return locations.map(location => {
|
||||
let resource = this.client.asUrl(location.file);
|
||||
const resource = this.client.asUrl(location.file);
|
||||
if (resource === null) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
@@ -12,26 +12,19 @@ import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
|
||||
export default class TypeScriptDocumentHighlightProvider implements DocumentHighlightProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
}
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public provideDocumentHighlights(resource: TextDocument, position: Position, token: CancellationToken): Promise<DocumentHighlight[]> {
|
||||
const filepath = this.client.normalizePath(resource.uri);
|
||||
if (!filepath) {
|
||||
return Promise.resolve<DocumentHighlight[]>([]);
|
||||
}
|
||||
let args: Proto.FileLocationRequestArgs = {
|
||||
const args: Proto.FileLocationRequestArgs = {
|
||||
file: filepath,
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve<DocumentHighlight[]>([]);
|
||||
}
|
||||
return this.client.execute('occurrences', args, token).then((response): DocumentHighlight[] => {
|
||||
let data = response.body;
|
||||
if (data && data.length) {
|
||||
|
||||
@@ -32,24 +32,17 @@ function textSpan2Range(value: Proto.TextSpan): Range {
|
||||
}
|
||||
|
||||
export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
}
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public provideDocumentSymbols(resource: TextDocument, token: CancellationToken): Promise<SymbolInformation[]> {
|
||||
const filepath = this.client.normalizePath(resource.uri);
|
||||
if (!filepath) {
|
||||
return Promise.resolve<SymbolInformation[]>([]);
|
||||
}
|
||||
let args: Proto.FileRequestArgs = {
|
||||
const args: Proto.FileRequestArgs = {
|
||||
file: filepath
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve<SymbolInformation[]>([]);
|
||||
}
|
||||
|
||||
function convertNavBar(indent: number, foldingMap: ObjectMap<SymbolInformation>, bucket: SymbolInformation[], item: Proto.NavigationBarItem, containerLabel?: string): void {
|
||||
let realIndent = indent + item.indent;
|
||||
|
||||
@@ -70,13 +70,12 @@ namespace Configuration {
|
||||
}
|
||||
|
||||
export default class TypeScriptFormattingProvider implements DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
private config: Configuration;
|
||||
private formatOptions: { [key: string]: Proto.FormatCodeSettings | undefined; };
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient
|
||||
) {
|
||||
this.config = Configuration.def();
|
||||
this.formatOptions = Object.create(null);
|
||||
Workspace.onDidCloseTextDocument((textDocument) => {
|
||||
@@ -143,7 +142,7 @@ export default class TypeScriptFormattingProvider implements DocumentRangeFormat
|
||||
if (!absPath) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
let args: Proto.FormatRequestArgs = {
|
||||
const args: Proto.FormatRequestArgs = {
|
||||
file: absPath,
|
||||
line: range.start.line + 1,
|
||||
offset: range.start.character + 1,
|
||||
|
||||
@@ -12,7 +12,8 @@ import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
export default class TypeScriptHoverProvider implements HoverProvider {
|
||||
|
||||
public constructor(private client: ITypescriptServiceClient) { }
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public provideHover(document: TextDocument, position: Position, token: CancellationToken): Promise<Hover | undefined | null> {
|
||||
const filepath = this.client.normalizePath(document.uri);
|
||||
@@ -24,9 +25,6 @@ export default class TypeScriptHoverProvider implements HoverProvider {
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return this.client.execute('quickinfo', args, token).then((response): Hover | undefined => {
|
||||
if (response && response.body) {
|
||||
const data = response.body;
|
||||
|
||||
@@ -11,45 +11,35 @@ import * as Proto from '../protocol';
|
||||
import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
export default class TypeScriptReferenceSupport implements ReferenceProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
|
||||
public tokens: string[] = [];
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
}
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public provideReferences(document: TextDocument, position: Position, options: { includeDeclaration: boolean }, token: CancellationToken): Promise<Location[]> {
|
||||
const filepath = this.client.normalizePath(document.uri);
|
||||
if (!filepath) {
|
||||
return Promise.resolve<Location[]>([]);
|
||||
}
|
||||
let args: Proto.FileLocationRequestArgs = {
|
||||
const args: Proto.FileLocationRequestArgs = {
|
||||
file: filepath,
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve<Location[]>([]);
|
||||
}
|
||||
const apiVersion = this.client.apiVersion;
|
||||
return this.client.execute('references', args, token).then((msg) => {
|
||||
let result: Location[] = [];
|
||||
const result: Location[] = [];
|
||||
if (!msg.body) {
|
||||
return result;
|
||||
}
|
||||
let refs = msg.body.refs;
|
||||
const refs = msg.body.refs;
|
||||
for (let i = 0; i < refs.length; i++) {
|
||||
let ref = refs[i];
|
||||
const ref = refs[i];
|
||||
if (!options.includeDeclaration && apiVersion.has203Features() && ref.isDefinition) {
|
||||
continue;
|
||||
}
|
||||
let url = this.client.asUrl(ref.file);
|
||||
let location = new Location(
|
||||
const url = this.client.asUrl(ref.file);
|
||||
const location = new Location(
|
||||
url,
|
||||
new Range(ref.start.line - 1, ref.start.offset - 1, ref.end.line - 1, ref.end.offset - 1)
|
||||
);
|
||||
new Range(ref.start.line - 1, ref.start.offset - 1, ref.end.line - 1, ref.end.offset - 1));
|
||||
result.push(location);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -30,7 +30,8 @@ export default class TypeScriptReferencesCodeLensProvider implements CodeLensPro
|
||||
|
||||
private onDidChangeCodeLensesEmitter = new EventEmitter<void>();
|
||||
|
||||
public constructor(private client: ITypescriptServiceClient) { }
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public get onDidChangeCodeLenses(): Event<void> {
|
||||
return this.onDidChangeCodeLensesEmitter.event;
|
||||
|
||||
@@ -11,45 +11,36 @@ import * as Proto from '../protocol';
|
||||
import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
export default class TypeScriptRenameProvider implements RenameProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
|
||||
public tokens: string[] = [];
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
}
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): Promise<WorkspaceEdit | undefined | null> {
|
||||
const filepath = this.client.normalizePath(document.uri);
|
||||
if (!filepath) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let args: Proto.RenameRequestArgs = {
|
||||
const args: Proto.RenameRequestArgs = {
|
||||
file: filepath,
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1,
|
||||
findInStrings: false,
|
||||
findInComments: false
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return this.client.execute('rename', args, token).then((response) => {
|
||||
let renameResponse = response.body;
|
||||
const renameResponse = response.body;
|
||||
if (!renameResponse) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let renameInfo = renameResponse.info;
|
||||
let result = new WorkspaceEdit();
|
||||
const renameInfo = renameResponse.info;
|
||||
const result = new WorkspaceEdit();
|
||||
|
||||
if (!renameInfo.canRename) {
|
||||
return Promise.reject<WorkspaceEdit>(renameInfo.localizedErrorMessage);
|
||||
}
|
||||
|
||||
renameResponse.locs.forEach((spanGroup) => {
|
||||
let resource = this.client.asUrl(spanGroup.file);
|
||||
const resource = this.client.asUrl(spanGroup.file);
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,38 +13,29 @@ import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
export default class TypeScriptSignatureHelpProvider implements SignatureHelpProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
|
||||
public constructor(client: ITypescriptServiceClient) {
|
||||
this.client = client;
|
||||
}
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient) { }
|
||||
|
||||
public provideSignatureHelp(document: TextDocument, position: Position, token: CancellationToken): Promise<SignatureHelp | undefined | null> {
|
||||
const filepath = this.client.normalizePath(document.uri);
|
||||
if (!filepath) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let args: Proto.SignatureHelpRequestArgs = {
|
||||
const args: Proto.SignatureHelpRequestArgs = {
|
||||
file: filepath,
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1
|
||||
};
|
||||
if (!args.file) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return this.client.execute('signatureHelp', args, token).then((response) => {
|
||||
let info = response.body;
|
||||
const info = response.body;
|
||||
if (!info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let result = new SignatureHelp();
|
||||
const result = new SignatureHelp();
|
||||
result.activeSignature = info.selectedItemIndex;
|
||||
result.activeParameter = info.argumentIndex;
|
||||
|
||||
if (info.items[info.selectedItemIndex].isVariadic) {
|
||||
}
|
||||
|
||||
info.items.forEach((item, i) => {
|
||||
if (!info) {
|
||||
return;
|
||||
@@ -55,12 +46,11 @@ export default class TypeScriptSignatureHelpProvider implements SignatureHelpPro
|
||||
result.activeParameter = Math.min(info.argumentIndex, item.parameters.length - 1);
|
||||
}
|
||||
|
||||
let signature = new SignatureInformation('');
|
||||
const signature = new SignatureInformation('');
|
||||
signature.label += Previewer.plain(item.prefixDisplayParts);
|
||||
|
||||
item.parameters.forEach((p, i, a) => {
|
||||
|
||||
let parameter = new ParameterInformation(
|
||||
const parameter = new ParameterInformation(
|
||||
Previewer.plain(p.displayParts),
|
||||
Previewer.plain(p.documentation));
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, Sym
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypescriptServiceClient } from '../typescriptService';
|
||||
|
||||
let _kindMapping: { [kind: string]: SymbolKind } = Object.create(null);
|
||||
const _kindMapping: { [kind: string]: SymbolKind } = Object.create(null);
|
||||
_kindMapping['method'] = SymbolKind.Method;
|
||||
_kindMapping['enum'] = SymbolKind.Enum;
|
||||
_kindMapping['function'] = SymbolKind.Function;
|
||||
@@ -19,14 +19,9 @@ _kindMapping['interface'] = SymbolKind.Interface;
|
||||
_kindMapping['var'] = SymbolKind.Variable;
|
||||
|
||||
export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbolProvider {
|
||||
|
||||
private client: ITypescriptServiceClient;
|
||||
private modeId: string;
|
||||
|
||||
public constructor(client: ITypescriptServiceClient, modeId: string) {
|
||||
this.client = client;
|
||||
this.modeId = modeId;
|
||||
}
|
||||
public constructor(
|
||||
private client: ITypescriptServiceClient,
|
||||
private modeId: string) { }
|
||||
|
||||
public provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<SymbolInformation[]> {
|
||||
// typescript wants to have a resource even when asking
|
||||
|
||||
@@ -52,12 +52,12 @@ interface LanguageDescription {
|
||||
}
|
||||
|
||||
export function activate(context: ExtensionContext): void {
|
||||
let MODE_ID_TS = 'typescript';
|
||||
let MODE_ID_TSX = 'typescriptreact';
|
||||
let MODE_ID_JS = 'javascript';
|
||||
let MODE_ID_JSX = 'javascriptreact';
|
||||
const MODE_ID_TS = 'typescript';
|
||||
const MODE_ID_TSX = 'typescriptreact';
|
||||
const MODE_ID_JS = 'javascript';
|
||||
const MODE_ID_JSX = 'javascriptreact';
|
||||
|
||||
let clientHost = new TypeScriptServiceClientHost([
|
||||
const clientHost = new TypeScriptServiceClientHost([
|
||||
{
|
||||
id: 'typescript',
|
||||
diagnosticSource: 'ts',
|
||||
@@ -74,7 +74,7 @@ export function activate(context: ExtensionContext): void {
|
||||
}
|
||||
], context.storagePath, context.globalState, context.workspaceState);
|
||||
|
||||
let client = clientHost.serviceClient;
|
||||
const client = clientHost.serviceClient;
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('typescript.reloadProjects', () => {
|
||||
clientHost.reloadProjects();
|
||||
@@ -103,7 +103,6 @@ const validateSetting = 'validate.enable';
|
||||
|
||||
class LanguageProvider {
|
||||
|
||||
private description: LanguageDescription;
|
||||
private extensions: ObjectMap<boolean>;
|
||||
private syntaxDiagnostics: ObjectMap<Diagnostic[]>;
|
||||
private currentDiagnostics: DiagnosticCollection;
|
||||
@@ -117,8 +116,10 @@ class LanguageProvider {
|
||||
|
||||
private _validate: boolean;
|
||||
|
||||
constructor(private client: TypeScriptServiceClient, description: LanguageDescription) {
|
||||
this.description = description;
|
||||
constructor(
|
||||
private client: TypeScriptServiceClient,
|
||||
private description: LanguageDescription
|
||||
) {
|
||||
this.extensions = Object.create(null);
|
||||
description.extensions.forEach(extension => this.extensions[extension] = true);
|
||||
this._validate = true;
|
||||
@@ -146,7 +147,7 @@ class LanguageProvider {
|
||||
}
|
||||
|
||||
private registerProviders(client: TypeScriptServiceClient): void {
|
||||
let config = workspace.getConfiguration(this.id);
|
||||
const config = workspace.getConfiguration(this.id);
|
||||
|
||||
this.completionItemProvider = new CompletionItemProvider(client, this.typingsStatus);
|
||||
this.completionItemProvider.updateConfiguration();
|
||||
@@ -172,7 +173,7 @@ class LanguageProvider {
|
||||
}
|
||||
|
||||
this.description.modeIds.forEach(modeId => {
|
||||
let selector: DocumentFilter = modeId;
|
||||
const selector: DocumentFilter = modeId;
|
||||
languages.registerCompletionItemProvider(selector, this.completionItemProvider, '.');
|
||||
languages.registerHoverProvider(selector, hoverProvider);
|
||||
languages.registerDefinitionProvider(selector, definitionProvider);
|
||||
@@ -249,7 +250,7 @@ class LanguageProvider {
|
||||
}
|
||||
|
||||
private configurationChanged(): void {
|
||||
let config = workspace.getConfiguration(this.id);
|
||||
const config = workspace.getConfiguration(this.id);
|
||||
this.updateValidate(config.get(validateSetting, true));
|
||||
if (this.completionItemProvider) {
|
||||
this.completionItemProvider.updateConfiguration();
|
||||
@@ -270,11 +271,11 @@ class LanguageProvider {
|
||||
}
|
||||
|
||||
public handles(file: string): boolean {
|
||||
let extension = path.extname(file);
|
||||
const extension = path.extname(file);
|
||||
if ((extension && this.extensions[extension]) || this.bufferSyncSupport.handles(file)) {
|
||||
return true;
|
||||
}
|
||||
let basename = path.basename(file);
|
||||
const basename = path.basename(file);
|
||||
return !!basename && basename === this.description.configFile;
|
||||
}
|
||||
|
||||
@@ -316,7 +317,7 @@ class LanguageProvider {
|
||||
}
|
||||
|
||||
public semanticDiagnosticsReceived(file: string, diagnostics: Diagnostic[]): void {
|
||||
let syntaxMarkers = this.syntaxDiagnostics[file];
|
||||
const syntaxMarkers = this.syntaxDiagnostics[file];
|
||||
if (syntaxMarkers) {
|
||||
delete this.syntaxDiagnostics[file];
|
||||
diagnostics = syntaxMarkers.concat(diagnostics);
|
||||
@@ -469,7 +470,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
|
||||
}
|
||||
|
||||
private createMarkerDatas(diagnostics: Proto.Diagnostic[], source: string): Diagnostic[] {
|
||||
let result: Diagnostic[] = [];
|
||||
const result: Diagnostic[] = [];
|
||||
for (let diagnostic of diagnostics) {
|
||||
let { start, end, text } = diagnostic;
|
||||
let range = new Range(start.line - 1, start.offset - 1, end.line - 1, end.offset - 1);
|
||||
|
||||
@@ -22,7 +22,7 @@ import * as is from './utils/is';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
let localize = nls.loadMessageBundle();
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
interface CallbackItem {
|
||||
c: (value: any) => void;
|
||||
|
||||
Reference in New Issue
Block a user