diff --git a/src/services/completions.ts b/src/services/completions.ts index 4193e651a037f..d9b197c3d27c3 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2045,7 +2045,7 @@ function completionEntryDataToSymbolOriginInfo(data: CompletionEntryData, comple function getInsertTextAndReplacementSpanForImportCompletion(name: string, importStatementCompletion: ImportStatementCompletionInfo, origin: SymbolOriginInfoResolvedExport, useSemicolons: boolean, sourceFile: SourceFile, options: CompilerOptions, preferences: UserPreferences) { const replacementSpan = importStatementCompletion.replacementSpan; - const quotedModuleSpecifier = quote(sourceFile, preferences, origin.moduleSpecifier); + const quotedModuleSpecifier = quote(sourceFile, preferences, escapeSnippetText(origin.moduleSpecifier)); const exportKind = origin.isDefaultExport ? ExportKind.Default : origin.exportName === InternalSymbolName.ExportEquals ? ExportKind.ExportEquals : diff --git a/tests/baselines/reference/importStatementCompletions3.baseline b/tests/baselines/reference/importStatementCompletions3.baseline new file mode 100644 index 0000000000000..854039fecf8ee --- /dev/null +++ b/tests/baselines/reference/importStatementCompletions3.baseline @@ -0,0 +1,106 @@ +=== /tests/cases/fourslash/./bar.ts === +// import f +// ^ +// | ---------------------------------------------------------------------- +// | function foo(): void +// | type +// | ---------------------------------------------------------------------- + +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/./bar.ts", + "position": 8, + "name": "" + }, + "item": { + "flags": 11, + "isGlobalCompletion": false, + "isMemberCompletion": false, + "isNewIdentifierLocation": true, + "optionalReplacementSpan": { + "start": 7, + "length": 1 + }, + "entries": [ + { + "name": "foo", + "kind": "function", + "kindModifiers": "export", + "sortText": "11", + "source": [ + { + "text": "./$foo", + "kind": "text" + } + ], + "insertText": "import { foo$1 } from \"./\\\\$foo\";", + "replacementSpan": { + "start": 0, + "length": 8 + }, + "sourceDisplay": [ + { + "text": "./$foo", + "kind": "text" + } + ], + "isSnippet": true, + "isImportStatementCompletion": true, + "data": { + "exportName": "foo", + "moduleSpecifier": "./$foo", + "fileName": "/tests/cases/fourslash/$foo.ts" + }, + "displayParts": [ + { + "text": "function", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "foo", + "kind": "functionName" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "void", + "kind": "keyword" + } + ], + "documentation": [] + }, + { + "name": "type", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + } + ] + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/importStatementCompletions3.ts b/tests/cases/fourslash/importStatementCompletions3.ts new file mode 100644 index 0000000000000..d212b10e033f7 --- /dev/null +++ b/tests/cases/fourslash/importStatementCompletions3.ts @@ -0,0 +1,14 @@ +/// + +// @Filename: ./$foo.ts +////export function foo() {} + +// @Filename: ./bar.ts +////import f/**/ + +verify.baselineCompletions({ + includeCompletionsForImportStatements: true, + includeCompletionsForModuleExports: true, + includeCompletionsWithSnippetText: true, + includeCompletionsWithInsertText: true +});