[css] path completion sometimes only works for one folder level. Fixes #46722

This commit is contained in:
Martin Aeschlimann
2018-03-29 15:20:30 +02:00
parent f50b6d7f13
commit 11f5d549db
5 changed files with 94 additions and 25 deletions

View File

@@ -69,16 +69,11 @@ function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?:
}
const lastIndexOfSlash = valueBeforeCursor.lastIndexOf('/');
let parentDir: string;
if (lastIndexOfSlash === -1) {
parentDir = path.resolve(root);
} else {
const valueBeforeLastSlash = valueBeforeCursor.slice(0, lastIndexOfSlash + 1);
const valueBeforeLastSlash = valueBeforeCursor.slice(0, lastIndexOfSlash + 1);
parentDir = startsWith(valueBeforeCursor, '/')
? path.resolve(root, '.' + valueBeforeLastSlash)
: path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
}
const parentDir = startsWith(valueBeforeCursor, '/')
? path.resolve(root, '.' + valueBeforeLastSlash)
: path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
try {
return fs.readdirSync(parentDir).map(f => {

View File

@@ -166,6 +166,7 @@ suite('HTML Path Completion', () => {
});
test('Empty Path Value', () => {
// document: index.html
testCompletionFor('<script src="|">', {
items: [
{ label: 'about/', resultText: '<script src="about/">' },
@@ -173,8 +174,15 @@ suite('HTML Path Completion', () => {
{ label: 'src/', resultText: '<script src="src/">' },
]
}, indexHtmlUri);
// document: about.html
testCompletionFor('<script src="|">', {
items: [
{ label: 'about.css', resultText: '<script src="about.css">' },
{ label: 'about.html', resultText: '<script src="about.html">' },
{ label: 'media/', resultText: '<script src="media/">' },
]
}, aboutHtmlUri);
});
test('Incomplete Path', () => {
testCompletionFor('<script src="/src/f|">', {
items: [
@@ -192,6 +200,7 @@ suite('HTML Path Completion', () => {
});
test('No leading dot or slash', () => {
// document: index.html
testCompletionFor('<script src="s|">', {
items: [
{ label: 'about/', resultText: '<script src="about/">' },
@@ -213,9 +222,31 @@ suite('HTML Path Completion', () => {
{ label: 'test.js', resultText: '<script src="src/test.js">' },
]
}, indexHtmlUri, [fixtureWorkspace]);
// document: about.html
testCompletionFor('<script src="s|">', {
items: [
{ label: 'about.css', resultText: '<script src="about.css">' },
{ label: 'about.html', resultText: '<script src="about.html">' },
{ label: 'media/', resultText: '<script src="media/">' },
]
}, aboutHtmlUri, [fixtureWorkspace]);
testCompletionFor('<script src="media/|">', {
items: [
{ label: 'icon.pic', resultText: '<script src="media/icon.pic">' }
]
}, aboutHtmlUri, [fixtureWorkspace]);
testCompletionFor('<script src="media/f|">', {
items: [
{ label: 'icon.pic', resultText: '<script src="media/icon.pic">' }
]
}, aboutHtmlUri, [fixtureWorkspace]);
});
test('Trigger completion in middle of path', () => {
// document: index.html
testCompletionFor('<script src="src/f|eature.js">', {
items: [
{ label: 'feature.js', resultText: '<script src="src/feature.js">' },
@@ -230,8 +261,24 @@ suite('HTML Path Completion', () => {
{ label: 'src/', resultText: '<script src="src/">' },
]
}, indexHtmlUri, [fixtureWorkspace]);
// document: about.html
testCompletionFor('<script src="media/f|eature.js">', {
items: [
{ label: 'icon.pic', resultText: '<script src="media/icon.pic">' }
]
}, aboutHtmlUri, [fixtureWorkspace]);
testCompletionFor('<script src="m|edia/feature.js">', {
items: [
{ label: 'about.css', resultText: '<script src="about.css">' },
{ label: 'about.html', resultText: '<script src="about.html">' },
{ label: 'media/', resultText: '<script src="media/">' },
]
}, aboutHtmlUri, [fixtureWorkspace]);
});
test('Trigger completion in middle of path and with whitespaces', () => {
testCompletionFor('<script src="./| about/about.html>', {
items: [

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.
*--------------------------------------------------------------------------------------------*/