Do not suggest own file for path completion. Fix #57384

This commit is contained in:
Pine Wu
2018-08-28 16:28:52 -07:00
parent 189a22d942
commit 9b751193a4
2 changed files with 7 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ export function getPathCompletionParticipant(
}
});
}
result.items = [...suggestions, ...result.items];
}
};
@@ -66,8 +67,13 @@ function providePathSuggestions(pathValue: string, position: Position, range: Ra
? fullValue.slice(0, position.character - (range.start.character + 1))
: fullValue.slice(0, position.character - range.start.character);
const workspaceRoot = resolveWorkspaceRoot(document, workspaceFolders);
const currentDocFsPath = URI.parse(document.uri).fsPath;
const paths = providePaths(valueBeforeCursor, currentDocFsPath, workspaceRoot).filter(p => {
// Exclude current doc's path
return path.resolve(currentDocFsPath, '../', p) !== currentDocFsPath;
});
const paths = providePaths(valueBeforeCursor, URI.parse(document.uri).fsPath, workspaceRoot);
const fullValueRange = isValueQuoted ? shiftRange(range, 1, -1) : range;
const replaceRange = pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange);

View File

@@ -95,7 +95,6 @@ suite('Completions', () => {
assertCompletions(`html { background-image: url('|')`, {
items: [
{ label: 'about.css', resultText: `html { background-image: url('about.css')` },
{ label: 'about.html', resultText: `html { background-image: url('about.html')` },
]
}, testUri, folders);
@@ -156,7 +155,6 @@ suite('Completions', () => {
assertCompletions(`@import './|'`, {
items: [
{ label: 'about.css', resultText: `@import './about.css'` },
{ label: 'about.html', resultText: `@import './about.html'` },
]
}, testUri, folders);