diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index ae1c645c03e..f3c1023c18c 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -257,7 +257,7 @@ }, "keybindings": { "key": ".", - "command": "^acceptSelectedSuggestion", + "command": "typescript.tryAcceptSelectedSuggestionOnDot", "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'typescript' && suggestionSupportsAcceptOnKey" }, "commands": [ @@ -268,6 +268,10 @@ { "command": "javascript.reloadProjects", "title": "%javascript.reloadProjects.title%" + }, + { + "command": "typescript.tryAcceptSelectedSuggestionOnDot", + "title": "%typescript.tryAcceptSelectedSuggestionOnDot.title%" } ], "breakpoints": [ diff --git a/extensions/typescript/package.nls.json b/extensions/typescript/package.nls.json index 1834876a6d9..cfbe862122f 100644 --- a/extensions/typescript/package.nls.json +++ b/extensions/typescript/package.nls.json @@ -12,6 +12,7 @@ "typescript.tsserver.experimentalAutoBuild": "Enables experimental auto build. Requires 1.9 dev or 2.x tsserver version and a restart of VS Code after changing it.", "typescript.validate.enable": "Enable/disable TypeScript validation.", "typescript.format.enable": "Enable/disable default TypeScript formatter.", + "typescript.tryAcceptSelectedSuggestionOnDot": "Accept current suggestion when a dot is typed", "javascript.format.enable": "Enable/disable default JavaScript formatter.", "format.insertSpaceAfterCommaDelimiter": "Defines space handling after a comma delimiter.", "format.insertSpaceAfterSemicolonInForStatements": " Defines space handling after a semicolon in a for statement.", diff --git a/extensions/typescript/src/typescriptMain.ts b/extensions/typescript/src/typescriptMain.ts index 02891af3f94..f8e5908a393 100644 --- a/extensions/typescript/src/typescriptMain.ts +++ b/extensions/typescript/src/typescriptMain.ts @@ -9,7 +9,7 @@ * ------------------------------------------------------------------------------------------ */ 'use strict'; -import { env, languages, commands, workspace, window, Uri, ExtensionContext, Memento, IndentAction, Diagnostic, DiagnosticCollection, Range, DocumentFilter, Disposable } from 'vscode'; +import { env, languages, commands, workspace, window, Uri, ExtensionContext, Memento, IndentAction, Diagnostic, DiagnosticCollection, Range, DocumentFilter, Disposable, Position } from 'vscode'; // This must be the first statement otherwise modules might got loaded with // the wrong locale. @@ -83,6 +83,18 @@ export function activate(context: ExtensionContext): void { clientHost.reloadProjects(); })); + context.subscriptions.push(commands.registerCommand('typescript.tryAcceptSelectedSuggestionOnDot', () => { + // When typing a dot, make sure the character before the dot is a valid indentifier character. + const editor = window.activeTextEditor; + if (editor && editor.selection && editor.selection.start.character >= 1) { + const preText = editor.document.getText(new Range(new Position(editor.selection.start.line, 0), new Position(editor.selection.start.line, editor.selection.start.character - 1))); + if (preText.match(/[a-z_$]\s*$/ig)) { + return commands.executeCommand('acceptSelectedSuggestion'); + } + } + return commands.executeCommand('type', { text: '.' }); + })); + window.onDidChangeActiveTextEditor(VersionStatus.showHideStatus, null, context.subscriptions); client.onReady().then(() => { context.subscriptions.push(ProjectStatus.create(client,