Skip to content

Html path completion. Fix #2037 - #44144

Merged
Martin Aeschlimann (aeschli) merged 13 commits into
masterfrom
octref/html-path-completion
Feb 26, 2018
Merged

Martin Aeschlimann (aeschli) merged 13 commits into
masterfrom
octref/html-path-completion

Conversation

@octref

@octref Pine (octref) commented Feb 21, 2018 •

Copy link
Copy Markdown
Contributor

Todo:

  • Generate replace TextEdit for current CompletionItem's
  • Add unit test against pathCompletion.ts
  • Add baseUrl configuration for computing root path for completions like /

) {
return {
onHtmlAttributeValue: (tag, attributeName, attributeValue) => {
const pathTagAndAttribute: { [t: string]: string } = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better declare outside of function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only remove quotes are start and end, also should decode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('/')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract to a function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@octref

Copy link
Copy Markdown
Contributor Author

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract to variable: value.lastIndexOf('/')


const valueAfterLastSlash = value.slice(value.lastIndexOf('/') + 1);
const valueBeforeLastSlash = value.slice(0, value.lastIndexOf('/') + 1);
const parentDir = startsWith(value, '/')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To resolve a path in a document, have a look at resolveReference.
It's what is used for document links.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the 'slice' is here. Also, shouldn't there be a replace of the last segment after the slash?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of 'insertText' we should use 'textEdit' as to not rely on the work regexp.
(and to make the result testable)

Comment thread extensions/html/server/tsconfig.json Outdated
"sourceMap": true,
"lib": [
"es5", "es2015.promise"
"es5", "es2015.promise", "dom"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

@aeschli Martin Aeschlimann (aeschli) Feb 23, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should run npm run compile in 'html/server'. Or just run npm run watch in vscode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the gulp compile-extension:html-server is not using the tsconfig here then why do we have the tsconfig here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@aeschli Martin Aeschlimann (aeschli) Feb 23, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread extensions/html/server/test/mocha.opts Outdated
--useColors true
./out/test No newline at end of file
./out/test
./out/test/pathCompletion No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to see a test that applies the result to the document.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll convert the insertText to textEdit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@octref Pine (octref) changed the title [WIP] Html path completion. Fix #2037 Html path completion. Fix #2037 Feb 23, 2018
@octref
Pine (octref) deleted the octref/html-path-completion branch March 14, 2018 18:06
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants