fix(52543): Module specifier should be escaped for snippet in import statement completion (#52574)

This commit is contained in:
Oleksandr T 2023-02-02 21:27:10 +02:00 committed by GitHub
parent 4ec9b2f8d7
commit e7dfe82cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 121 additions and 1 deletions

View File

@ -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 :

View File

@ -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"
}
]
}
]
}
}
]

View File

@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />
// @Filename: ./$foo.ts
////export function foo() {}
// @Filename: ./bar.ts
////import f/**/
verify.baselineCompletions({
includeCompletionsForImportStatements: true,
includeCompletionsForModuleExports: true,
includeCompletionsWithSnippetText: true,
includeCompletionsWithInsertText: true
});