Do not suggest dot files in html/css. Fix #46780

This commit is contained in:
Pine Wu
2018-09-18 11:38:09 -07:00
parent 9040bf6802
commit 39fbbf02c4
6 changed files with 37 additions and 7 deletions

View File

@@ -69,10 +69,15 @@ function providePathSuggestions(pathValue: string, position: Position, range: Ra
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, currentDocFsPath, workspaceRoot)
.filter(p => {
// Exclude current doc's path
return path.resolve(currentDocFsPath, '../', p) !== currentDocFsPath;
})
.filter(p => {
// Exclude paths that start with `.`
return p[0] !== '.';
});
const fullValueRange = isValueQuoted ? shiftRange(range, 1, -1) : range;
const replaceRange = pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange);

View File

@@ -193,4 +193,14 @@ suite('Completions', () => {
]
}, testSCSSUri, folders, 'scss');
});
test('Completion should ignore files/folders starting with dot', function () {
let testUri = Uri.file(path.resolve(__dirname, '../../test/pathCompletionFixtures/about/about.css')).toString();
let folders = [{ name: 'x', uri: Uri.file(path.resolve(__dirname, '../../test')).toString() }];
assertCompletions('html { background-image: url("../|")', {
count: 4
}, testUri, folders);
});
});

View File

@@ -0,0 +1,4 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

View File

@@ -78,11 +78,12 @@ function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?:
}
try {
return fs.readdirSync(parentDir).map(f => {
const paths = fs.readdirSync(parentDir).map(f => {
return isDir(path.resolve(parentDir, f))
? f + '/'
: f;
});
return paths.filter(p => p[0] !== '.');
} catch (e) {
return [];
}

View File

@@ -66,7 +66,7 @@ export function testCompletionFor(value: string, expected: { count?: number, ite
let list = mode.doComplete!(document, position);
if (expected.count) {
assert.equal(list.items, expected.count);
assert.equal(list.items.length, expected.count);
}
if (expected.items) {
for (let item of expected.items) {
@@ -96,7 +96,7 @@ suite('HTML Path Completion', () => {
command: 'editor.action.triggerSuggest'
};
const fixtureRoot = path.resolve(__dirname, 'pathCompletionFixtures');
const fixtureRoot = path.resolve(__dirname, '../../src/test/pathCompletionFixtures');
const fixtureWorkspace = { name: 'fixture', uri: Uri.file(fixtureRoot).toString() };
const indexHtmlUri = Uri.file(path.resolve(fixtureRoot, 'index.html')).toString();
const aboutHtmlUri = Uri.file(path.resolve(fixtureRoot, 'about/about.html')).toString();
@@ -296,6 +296,12 @@ suite('HTML Path Completion', () => {
]
}, indexHtmlUri, [fixtureWorkspace]);
});
test('Completion should ignore files/folders starting with dot', () => {
testCompletionFor('<script src="./|"', {
count: 3
}, indexHtmlUri, [fixtureWorkspace]);
});
test('Unquoted Path', () => {
/* Unquoted value is not supported in html language service yet

View File

@@ -0,0 +1,4 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/