JetBrains/web-types

How to set the offset in the source property?

ddadon10 opened this issue · 2 comments

I am implementing Web types for my custom web components and I struggle to figure out which value "offset" should be set in order to get the "Go to definitions" working in IntelliJ.

Example:

{
      "elements": [
        {
          "name": "my-component",
          "description": "This is a custom web component",
          "source": {
            "file": "./MyComponent.js",
            "offset": 0
          },
          "pattern": {
            "or": ["my-component"]
          }
}

It is working if the class in MyComponent.js is the first line in the file:

class MyComponent extends LitElement {
...
}

But if it is the second line it does not work, for example:

define(["lit"], function ({LitElement}) {
    class MyComponent extends LitElement  {
    ...
    }
})

I tried setting offset to the following value: -1 0 1 2, without success.

How the offset should be set?

This feature rely on the definition of a "Symbol", like class or function.

I found a workaround by simply wrapping my function call with a function definition like:

function element () {
  define(["lit"], function ({LitElement}) {
      class MyComponent extends LitElement  {
      ...
      }
  })
}
element()

With that, "Go to definition" is working properly.

@ddadon10 - sorry for a much delayed response, but I was away. The offset needs to be set to the location of class keyword in the file, so that it can pick up the definition. I assume you are not exporting components from the file, otherwise you can simply provide symbol name.