Repository navigation
Outline and folding not displaying when provided via analyzer plugin #1981
Copy link
Copy link
Closed
Labels
in editorRelates to code editing or language featuresRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.An enhancement or improvement that should be listed in release notes but is not a bug fix.
Milestone
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in editorRelates to code editing or language featuresRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.An enhancement or improvement that should be listed in release notes but is not a bug fix.
Activity
DanTup commentedon Sep 7, 2019
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?).
simolus3 commentedon Sep 17, 2019
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.
DanTup commentedon Sep 17, 2019
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 hitF5. 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).simolus3 commentedon Sep 18, 2019
This is amazing, thanks! I managed to get some basic features working:

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.
analyzer.capabilities.supportsAnalyzingHtmlFilesappears to always be false (probably because we didn't connect yet, and the default version0.0.0doesn't report any compatibility). Did I overlook anything?Dart-Code/src/extension/extension.ts
Line 237 in f0ea703
DartDocumentSymbolProviderassumes that for each outline,outline.element.locationis defined, but it's optional in the analyzer protocol. I fixed it by replacingoutline.element.locationwithconst location = outline.element.location || outline;Dart-Code/src/extension/providers/dart_document_symbol_provider.ts
Line 28 in d908d0c
DanTup commentedon Sep 19, 2019
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!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.
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.
DanTup commentedon Sep 19, 2019
Dart-Code/src/extension.ts
Line 190 in f3509d0
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.