diff --git a/src/main.ts b/src/main.ts index 7675fde..89f204f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,7 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(HACK_MODE, new providers.HackDocumentSymbolProvider())); context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(new providers.HackWorkspaceSymbolProvider())); context.subscriptions.push(vscode.languages.registerDocumentHighlightProvider(HACK_MODE, new providers.HackDocumentHighlightProvider())); - context.subscriptions.push(vscode.languages.registerCompletionItemProvider(HACK_MODE, new providers.HackCompletionItemProvider(), '$', '>', ':')); + context.subscriptions.push(vscode.languages.registerCompletionItemProvider(HACK_MODE, new providers.HackCompletionItemProvider(), '$', '>', ':', '\\')); context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(HACK_MODE, new providers.HackDocumentFormattingEditProvider())); context.subscriptions.push(vscode.languages.registerReferenceProvider(HACK_MODE, new providers.HackReferenceProvider())); context.subscriptions.push(vscode.languages.registerDefinitionProvider(HACK_MODE, new providers.HackDefinitionProvider())); diff --git a/src/providers.ts b/src/providers.ts index 6487715..12ea4e0 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -130,9 +130,14 @@ export class HackCompletionItemProvider implements vscode.CompletionItemProvider kind = vscode.CompletionItemKind.Variable; labelType = labelType.split('\\').pop(); } else if (labelType.startsWith('(function')) { + // If the name and return type matches then it is a constructor + if (element.name === element.func_details.return_type) { + kind = vscode.CompletionItemKind.Constructor; + } else { + kind = vscode.CompletionItemKind.Method; + } const typeSplit = labelType.slice(1, labelType.length - 1).split(':'); labelType = typeSplit[0] + ': ' + typeSplit[1].split('\\').pop(); - kind = vscode.CompletionItemKind.Method; } else if (labelType === 'class') { kind = vscode.CompletionItemKind.Class; } @@ -163,9 +168,8 @@ export class HackDocumentFormattingEditProvider implements vscode.DocumentFormat } export class HackReferenceProvider implements vscode.ReferenceProvider { - public provideReferences(document: vscode.TextDocument, position: vscode.Position, context: vscode.ReferenceContext, - token: vscode.CancellationToken) - : Thenable { + public provideReferences(document: vscode.TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken) + : Thenable { const text = document.getText(); return hh_client.findLvarRefs(text, position.line + 1, position.character + 1).then(lvarRefs => { return hh_client.ideFindRefs(text, position.line + 1, position.character + 1).then(findRefs => { @@ -205,13 +209,13 @@ export class HackReferenceProvider implements vscode.ReferenceProvider { export class HackDefinitionProvider implements vscode.DefinitionProvider { public provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken) - : Thenable { + : Thenable { const text = document.getText(); return hh_client.ideGetDefinition(text, position.line + 1, position.character + 1).then(value => { const definition: vscode.Location[] = []; value.forEach(element => { if (element.definition_pos != null) { - const location : vscode.Location = new vscode.Location( + const location: vscode.Location = new vscode.Location( vscode.Uri.file(element.definition_pos.filename || document.fileName), new vscode.Range( new vscode.Position(element.definition_span.line_start - 1, element.definition_span.char_start - 1), diff --git a/src/proxy.ts b/src/proxy.ts index 6248ac1..05aab79 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -78,27 +78,46 @@ export function ideGetDefinition(text: string, line: number, character: number) filename: string, line: number, char_start: number, - char_end: number }, - definition_pos: { - filename: string, - line: number, - char_start: number, - char_end: number - }, - definition_span: { - filename: string, - line_start: number, - char_start: number, - line_end: number, - char_end: number - }, - definition_id: number + char_end: number + }, + definition_pos: { + filename: string, + line: number, + char_start: number, + char_end: number + }, + definition_span: { + filename: string, + line_start: number, + char_start: number, + line_end: number, + char_end: number + }, + definition_id: number }[]> { return run(['--ide-get-definition', line + ':' + character], text); } export function autoComplete(text: string, position: number) - : Thenable<{ name: string, type: string }[]> { // tslint:disable-line + : Thenable<{ + name: string, + type: string, // tslint:disable-line + pos: { + fileName: string, + line: number, + char_start: number, + char_end: number + }, + func_details: { + min_arity: number, + return_type: string, + params: { + name: string, + type: string, // tslint:disable-line + variadic: boolean + }[] + } + }[]> { // Insert hh_client autocomplete token at cursor position. const autoTok: string = 'AUTO332'; const input = [text.slice(0, position), autoTok, text.slice(position)].join('');