Allow opting into path completion from custom data · Issue #101 · microsoft/vscode-html-languageservice (original) (raw)

I am working on a web component for an internal project at work. I have documented the interface in a component.html-data.json file which team-members using VSCode can load into their editor. That works great - what a cool feature!

I have a src attribute, and I would like VS Code to help offer path completion.

A good example of the component would be https://github.com/gustafnk/h-include - it also has a src attribute that would benefit from having path completion.

{ "version": 1.1, "tags": [ { "name": "h-include", "description": "HTML include", "attributes": [ { "name": "src" } ] } ] }

The above JSON object works. And you can even control-click on the url in the attribute to go to the referenced file:

The control-clicking on the URL works as the htmlLinks.ts service just works on any href and src attribute:

| if (lastAttributeName === 'src' || lastAttributeName === 'href') { | | --------------------------------------------------------------------- |

But path completion does not work, as the isPathAttribute function of the pathCompletion.ts service use a hardcoded attribute map for where it should be enabled:

const PATH_TAG_AND_ATTR: { [tag: string]: string | string[] } = {
// HTML 4
a: 'href',
area: 'href',
body: 'background',
del: 'cite',
form: 'action',
frame: ['src', 'longdesc'],
img: ['src', 'longdesc'],
ins: 'cite',
link: 'href',
object: 'data',
q: 'cite',
script: 'src',
// HTML 5
audio: 'src',
button: 'formaction',
command: 'icon',
embed: 'src',
html: 'manifest',
input: ['src', 'formaction'],
source: 'src',
track: 'src',
video: ['src', 'poster']
};

It would be very nice if this could be made possible. I can think of two approaches off the top of my head:

  1. Extending customData to support attributes opting into pathCompletion. ... "attributes": { "name": "src", "pathCompletion": true } ...
  2. Using the same heuristic for enabling path completion as is done for html links - so having it enabled on any attribute named src or href.