mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
replace whole path if directory separator appears for import completion. (#41412)
* replace whole path if directory separator appears. * Fix. * revert change. * Fix test case. * add test. * fix as suggested. * revert useless change * adapt to code change. * fix baseline for test file.
This commit is contained in:
@@ -6,7 +6,7 @@ namespace ts {
|
||||
* we expect the host to correctly handle paths in our specified format.
|
||||
*/
|
||||
export const directorySeparator = "/";
|
||||
const altDirectorySeparator = "\\";
|
||||
export const altDirectorySeparator = "\\";
|
||||
const urlSchemeSeparator = "://";
|
||||
const backslashRegExp = /\\/g;
|
||||
|
||||
|
||||
@@ -279,7 +279,9 @@ namespace ts.Completions.StringCompletions {
|
||||
|
||||
function addReplacementSpans(text: string, textStart: number, names: readonly NameAndKind[]): readonly PathCompletion[] {
|
||||
const span = getDirectoryFragmentTextSpan(text, textStart);
|
||||
return names.map(({ name, kind, extension }): PathCompletion => ({ name, kind, extension, span }));
|
||||
const wholeSpan = text.length === 0 ? undefined : createTextSpan(textStart, text.length);
|
||||
return names.map(({ name, kind, extension }): PathCompletion =>
|
||||
Math.max(name.indexOf(directorySeparator), name.indexOf(altDirectorySeparator)) !== -1 ? { name, kind, extension, span: wholeSpan } : { name, kind, extension, span });
|
||||
}
|
||||
|
||||
function getStringLiteralCompletionsFromModuleNames(sourceFile: SourceFile, node: LiteralExpression, compilerOptions: CompilerOptions, host: LanguageServiceHost, typeChecker: TypeChecker): readonly PathCompletion[] {
|
||||
@@ -683,7 +685,7 @@ namespace ts.Completions.StringCompletions {
|
||||
|
||||
// Replace everything after the last directory separator that appears
|
||||
function getDirectoryFragmentTextSpan(text: string, textStart: number): TextSpan | undefined {
|
||||
const index = Math.max(text.lastIndexOf(directorySeparator), text.lastIndexOf("\\"));
|
||||
const index = Math.max(text.lastIndexOf(directorySeparator), text.lastIndexOf(altDirectorySeparator));
|
||||
const offset = index !== -1 ? index + 1 : 0;
|
||||
// If the range is an identifier, span is unnecessary.
|
||||
const length = text.length - offset;
|
||||
|
||||
Reference in New Issue
Block a user