Skip to content

Outline and folding not displaying when provided via analyzer plugin #1981

Closed

Description

@simolus3

In a Dart project, I have this file, test.moor:

CREATE TABLE playground (
  id INT NOT NULL PRIMARY KEY AUTOINCREMENT
)

I have added "moor" to the list of additional file endings to analyze and I also have the option to use the analysis server folding turned on. The server does send back outline and folding information (relevant excerpts from the instrumentation log):

1567872912626:Req:{"id"::"2","method"::"analysis.updateContent","params"::{"files"::{"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor"::{"content"::"CREATE TABLE playground (\n  id INT NOT NULL PRIMARY KEY AUTOINCREMENT\n)","type"::"add"}}},"clientRequestTime"::1567872911985}
1567872912643:Res:{"id"::"2","result"::{}}

1567872913157:Req:{"id"::"6","method"::"analysis.setSubscriptions","params"::{"subscriptions"::{"CLOSING_LABELS"::["/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor"],"FOLDING"::["/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor"],"OCCURRENCES"::["/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor"],"OUTLINE"::["/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor"]}},"clientRequestTime"::1567872912560}
1567872913167:Res:{"id"::"6"}

1567872835759:Noti:{"event"::"analysis.outline","params"::{"file"::"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor","kind"::"LIBRARY","outline"::{"element"::{"kind"::"FILE","name"::"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor","flags"::0},"offset"::0,"length"::71,"codeOffset"::0,"codeLength"::71,"children"::[{"element"::{"kind"::"CLASS","name"::"playground","flags"::0},"offset"::0,"length"::71,"codeOffset"::0,"codeLength"::71,"children"::[{"element"::{"kind"::"FIELD","name"::"id","flags"::0},"offset"::28,"length"::41,"codeOffset"::28,"codeLength"::41}]}]}}}

1567872930618:Noti:{"event"::"analysis.folding","params"::{"file"::"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor","regions"::[{"kind"::"CLASS_BODY","offset"::26,"length"::43}]}}
Formatted representation of the last two events for readability
{
   "event":"analysis.outline",
   "params":{
      "file":"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor",
      "kind":"LIBRARY",
      "outline":{
         "element":{
            "kind":"FILE",
            "name":"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor",
            "flags":0
         },
         "offset":0,
         "length":71,
         "codeOffset":0,
         "codeLength":71,
         "children":[
            {
               "element":{
                  "kind":"CLASS",
                  "name":"playground",
                  "flags":0
               },
               "offset":0,
               "length":71,
               "codeOffset":0,
               "codeLength":71,
               "children":[
                  {
                     "element":{
                        "kind":"FIELD",
                        "name":"id",
                        "flags":0
                     },
                     "offset":28,
                     "length":41,
                     "codeOffset":28,
                     "codeLength":41
                  }
               ]
            }
         ]
      }
   }
}

{
   "event":"analysis.folding",
   "params":{
      "file":"/home/simon/IdeaProjects/moor/extras/plugin_example/lib/test.moor",
      "regions":[
         {
            "kind":"CLASS_BODY",
            "offset":26,
            "length":43
         }
      ]
   }
}

However, the outline view from VS Code says "The active editor cannot provide outline information." and folding is not available inside the file.

Is there anything wrong with that's reported in the last two events that might cause DartCode to ignore them?
If there is file-ending check for these kinds of reports, this might be related to #1944

Activity

  1. DanTup commented on Sep 7, 2019

    @DanTup
    Member

    This is likely because we have to tell VS Code which documents (languages, etc.) our providers will provide data for:

    https://github.com/Dart-Code/Dart-Code/blob/master/src/extension/extension.ts#L236

    We already conditionally push HTML into there, however it gets a bit complicated because some of the providers are Dart-only:

    https://github.com/Dart-Code/Dart-Code/blob/master/src/extension/extension.ts#L258

    Without doing some digging, I'm not sure for certain whether it's safe to just add the custom extensions to any of those types that HTML is used for or not (I don't recall exactly what the issues are with adding HTML to all of them.. for ex. the implementation provider is only wired up for Dart, but I'm wondering why the server wouldn't just return no data for HTML and it'd be safe?).

  2. added
    in editorRelates to code editing or language features
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Sep 7, 2019
  3. added this to the v3.5.0 milestone on Sep 7, 2019
  4. simolus3 commented on Sep 17, 2019

    @simolus3
    ContributorAuthor

    Is there an update on this? If there's an uncertainty on how the analysis server is going to react when non-supported subscriptions are requested, would it help if I just try it out and see if that breaks anything?
    I know that there are other priorities, but I would love to see this in Dart Code so please let me know if there's any way I could help here.

  5. DanTup commented on Sep 17, 2019

    @DanTup
    Member

    Apologies - I've been out of the office last week and I'm still working through things I missed. I put this in the v3.5 milestone because I'd like to have a look at it for the next release, but I haven't gotten to it yet.

    I've got a busy week and will be out next week too, so if you want to have a go, it could certainly help things along. Running the extension from source should be easy - just clone this repo, run npm install, open the project in VS Code and hit F5. It'll spawn a new copy of VS Code that's running the extension from source. You could try modifying the lines mentioned above to include your file extension, and see if it works (you can use the analysis server log file, or Capture Logs commands to capture traffic to the server if required).

  6. simolus3 commented on Sep 18, 2019

    @simolus3
    ContributorAuthor

    This is amazing, thanks! I managed to get some basic features working:
    grafik

    I found a couple of issues, but it could be my plugin that's responsible for them. I will try to integrate more analysis providers and dig around some more. I can open a PR to solve the problems I run across.

    • In the following line, analyzer.capabilities.supportsAnalyzingHtmlFiles appears to always be false (probably because we didn't connect yet, and the default version 0.0.0 doesn't report any compatibility). Did I overlook anything?
      if (config.analyzeAngularTemplates && analyzer.capabilities.supportsAnalyzingHtmlFiles) {
    • DartDocumentSymbolProvider assumes that for each outline, outline.element.location is defined, but it's optional in the analyzer protocol. I fixed it by replacing outline.element.location with const location = outline.element.location || outline;
      toRange(document, outline.element.location.offset, outline.element.location.length),
    • Folding seems a bit weird, it doesn't recognize all available regions sometimes. I'll to find a better case to reproduce this
  7. DanTup commented on Sep 19, 2019

    @DanTup
    Member

    In the following line, analyzer.capabilities.supportsAnalyzingHtmlFiles appears to always be false (probably because we didn't connect yet, and the default version 0.0.0 doesn't report any compatibility).

    Ugh, this looks like a bug. You are correct that the capabilities are incorrect until the server has connected and announced its version (it should be inside the block // Setup that requires server version/capabilities.). I'll investigate when this broke.. if it's been that way for a while I'm surprised nobody has raised it!

    DartDocumentSymbolProvider assumes that for each outline, outline.element.location is defined, but it's optional in the analyzer protocol

    Yeah, this seems incorrect too. I'm slowly working away at enabling TS's strict mode that would highlight this, but I guess I haven't reviewed this file with it enabled. The fix seems reasonable to me.

    Folding seems a bit weird, it doesn't recognize all available regions sometimes.

    Hard to guess without an example - but it's worth bearing in mind that VS Code has limited folding capabilities - it only does line-folding, so things that overlap (or end/start on the same line) might not work correctly.

  8. DanTup commented on Sep 19, 2019

    @DanTup
    Member

    if (config.analyzeAngularTemplates && analyzer.capabilities.supportsAnalyzingHtmlFiles) {

    As far as I can tell, this has never worked properly :( Suggests not many are using this, but I'll fix it all the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions