Repository navigation
Html path completion. Fix #2037 - #44144
Conversation
| ) { | ||
| return { | ||
| onHtmlAttributeValue: (tag, attributeName, attributeValue) => { | ||
| const pathTagAndAttribute: { [t: string]: string } = { |
There was a problem hiding this comment.
better declare outside of function
There was a problem hiding this comment.
Compiled a list of them from #2037 (comment)
| const isDir = (p: string) => fs.statSync(p).isDirectory(); | ||
|
|
||
| if (pathTagAndAttribute[tag] && pathTagAndAttribute[tag] === attributeName) { | ||
| const currPath = attributeValue.replace(/['"]/g, ''); |
There was a problem hiding this comment.
only remove quotes are start and end, also should decode.
There was a problem hiding this comment.
Agree with quotes. Don't think we should decode since this is path completion not URI completion. I'll add a guard against https, http, //.
| const currPath = attributeValue.replace(/['"]/g, ''); | ||
|
|
||
| let resolvedPath; | ||
| if (currPath.startsWith('/')) { |
There was a problem hiding this comment.
extract to a function
|
Martin Aeschlimann (@aeschli) Do you mind taking a look. I'll do the baseurl as a separate PR. |
| return []; | ||
| } | ||
|
|
||
| const valueAfterLastSlash = value.slice(value.lastIndexOf('/') + 1); |
There was a problem hiding this comment.
extract to variable: value.lastIndexOf('/')
|
|
||
| const valueAfterLastSlash = value.slice(value.lastIndexOf('/') + 1); | ||
| const valueBeforeLastSlash = value.slice(0, value.lastIndexOf('/') + 1); | ||
| const parentDir = startsWith(value, '/') |
There was a problem hiding this comment.
To resolve a path in a document, have a look at resolveReference.
It's what is used for document links.
There was a problem hiding this comment.
I'm having it this way specifically for incomplete suggestions, such as ./f, I want it to suggest ./foo.js and have insertText as oo.js.
| ? path.resolve(root, '.' + valueBeforeLastSlash) | ||
| : path.resolve(activeDocFsPath, '..', valueBeforeLastSlash); | ||
|
|
||
| return fs.readdirSync(parentDir).map(f => { |
There was a problem hiding this comment.
handle the error? (e.g. directory does not exists)
| return { | ||
| label: f, | ||
| kind: isDir(path.resolve(parentDir, f)) ? CompletionItemKind.Folder : CompletionItemKind.File, | ||
| insertText: f.slice(valueAfterLastSlash.length) |
There was a problem hiding this comment.
I don't understand why the 'slice' is here. Also, shouldn't there be a replace of the last segment after the slash?
There was a problem hiding this comment.
Instead of 'insertText' we should use 'textEdit' as to not rely on the work regexp.
(and to make the result testable)
| "sourceMap": true, | ||
| "lib": [ | ||
| "es5", "es2015.promise" | ||
| "es5", "es2015.promise", "dom" |
There was a problem hiding this comment.
Is that intended?
There was a problem hiding this comment.
When I ran tsc -p server without this I got millions of errors like this:
lib/jquery.d.ts(2769,29): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2792,16): error TS2304: Cannot find name 'HTMLElement'.
lib/jquery.d.ts(2804,34): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2817,37): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2825,39): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2838,38): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2845,25): error TS2304: Cannot find name 'HTMLElement'.
lib/jquery.d.ts(2850,12): error TS2304: Cannot find name 'HTMLElement'.
lib/jquery.d.ts(2861,35): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2873,22): error TS2304: Cannot find name 'HTMLElement'.
lib/jquery.d.ts(2881,37): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2887,22): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2920,41): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2932,22): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2940,39): error TS2304: Cannot find name 'Element'.
lib/jquery.d.ts(2971,43): error TS2304: Cannot find name 'Element'.
There was a problem hiding this comment.
You should run npm run compile in 'html/server'. Or just run npm run watch in vscode
There was a problem hiding this comment.
If the gulp compile-extension:html-server is not using the tsconfig here then why do we have the tsconfig here?
There was a problem hiding this comment.
But if you don't like it we can change it back and put a dev README.md at /extensions/html, what do you think?
There was a problem hiding this comment.
tsconfig is still used by the typescript language server in VSCode.
I added an 'include' to tsconfig so that lib and other folders are ignored, so you won't see the error anymore.
How to compile vscode (including html server) is described in here. npm run watch is what should be used.
| --useColors true | ||
| ./out/test No newline at end of file | ||
| ./out/test | ||
| ./out/test/pathCompletion No newline at end of file |
There was a problem hiding this comment.
Should not be necessary when the file uses the right file extension: pathCompletion.test.ts
| assert.equal(suggestions[0].kind, CompletionItemKind.File); | ||
| assert.equal(suggestions[1].kind, CompletionItemKind.File); | ||
| }); | ||
| }); No newline at end of file |
There was a problem hiding this comment.
I'd love to see a test that applies the result to the document.
There was a problem hiding this comment.
I see. I'll convert the insertText to textEdit.
There was a problem hiding this comment.
Actually I forgot -- the reason I did it was for TextEdit, somehow the LS client filters out all the completion items if I do not give them a filterText, and I don't know what meaningful filterText to give to the items.
Yesterday when I was testing this, this happened only on insider, not stable.
You can try running this branch to see: https://github.com/Microsoft/vscode/tree/octref/html-path-completion-textedit
Todo:
TextEditfor currentCompletionItem'spathCompletion.tsbaseUrlconfiguration for computing root path for completions like/