Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline support #1

Closed
apjanke opened this issue Apr 26, 2023 · 6 comments
Closed

Outline support #1

apjanke opened this issue Apr 26, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@apjanke
Copy link

apjanke commented Apr 26, 2023

Hooray for this release!

Could we get Outline support in a future release? That's one of the feature I use the most with VS Code plugins for nontrivial code, and it doesn't seem to be supported here yet.

Outline view saying "No symbols found"

Requirements, Hopes, and Dreams

Semantic-level tree, instead of pure syntax: Matlab classdef syntax breaks the class definition in to separate properties, methods, events etc syntactic sections. And attributes like Access controls, Static, Hidden, and Constant are set per properties/methods/etc block, not on the individual properties etc. This means that, for me at least, nontrivial classdefs often get broken up in to many separate properties and methods blocks. If the outline tree has a level for properties/methods/etc., I'd like to see all the blocks of a given type (like, all the properties blocks, regardless of their attributes), combined in to a single node in the outline tree. Would make it easier to find things, see a combined list of all the things of a particular type, and save a lot of clicking to expand or collapse multiple tree nodes for a syntactic element.

I can say this from experience. Gimly's unofficial Matlab extension has Outline support, but as far as I can tell it always shows each distinct properties/methods/etc block as a distinct node in the tree. I find that makes it hard to navigate or view a classdef using the outline, at least with my coding style.

I did a little Matlab classdef outline view thing for MCodeNavigator a while back that works this way, combining all the methods or properties of a class under a single "Methods" or "Properties" node in the outline tree, regardless of whether they were lexcally inside the same methods or properties block. You can have a look at that if you'd like a concrete example of what I mean here.

image

(Those "/private" with a slash notations mean they're (GetAccess=public, SetAccess=private); mixed-mode access is shown as "getaccess/setaccess", and since public is the default value and pretty common, it is elided to avoid cluttering up the view.)

It would also be nice to have an option to elide the properties/methods/events level of tree nodes and show all the methods and properties directly under the class. But I'm guessing that shouldn't be the default.

Showing nested functions as sub-nodes under regular methods or functions would be a nice touch. Some of the code bases I work with make extensive use of nested functions, with lots of them inside a single large function, or even I think multi-level nesting.

Details and Considerations

I understand that Outline support is a significant feature and would take some work. But it would be really useful IMHO; personally, I would prioritize it.

My understanding is that there's two main ways to do outline support: in-extension grammar support, or using an external Language Server with LSP. And the LSP could be done as a standalone program, or using Matlab itself (and thus requiring a license) like some of the other features currently in this extension do. I could see advantages to all approaches:

  • in-extension could be simpler, easier to implement, and maybe more portable
  • Independent LSP program wouldn't require a Matlab license, which would be nice for editing Matlab code anywhere. Even if you have a Matlab license, you may be limited by activations on a Standalone license (this trips me up a lot), concurrency limitations on network licenses, OS support, or just whether Matlab is installed and ove the right version.
  • Using Matlab could let you use the Real Matlab language parser and execution engine to get the best info.

I see the blog post announcing this VS Code extension says you're already using Matlab as an LSP, so maybe it wouldn't be a huge stretch to do Outline support that way.

Language Versioning

Matlab syntax has changed substantially over the years with new Matlab releases. First classdef, and later string literals, class property validators,arguments blocks and their subfeatures, etc. Many Matlab developers target older releases or multiple releases. Would be nice to be able to select the right historical version of the syntax for the program you're using. I guess this applies to other features of this extension, too.

Using Matlab itself as an LSP for outlining might make this versioning easier, because selecting the right language version would basically be implicit in pointing the extension at your Matlab installation in its settings, like (I think) you already have to do?

References

@apjanke
Copy link
Author

apjanke commented Apr 26, 2023

(Sorry for the short issue description; I just really wanted to be the one to post issue #1. I'll flesh it out some more soon. ;) )

@zm-cttae
Copy link

zm-cttae commented Apr 26, 2023

The extension published by Gimly has multiple language features driven by inaccurate symbol data. They are contributed by shims/polyfills of common language providers.

List:

  • Document symbol provider
  • Peek definition provider
  • Workspace symbol provider

Tbh this is also a chance to make the impl accurate

@zm-cttae
Copy link

zm-cttae commented Apr 27, 2023

FWIW the reason the competing impl is inaccurate is a lack of accurate symbol resolution for OOP - especially package and classdef fields:

  • Functions and variables without a . are matched quite well.
    Class methods and package/namespace stuff is matched by last key name which "technically works" but isn't great.
    Metrics for definition accuracy and/or variable scoping aren't taken into account for the definition order.
  • I could be adding a hierarchial tree - AKA "trie" - to store the symbol data before symbol lookup.
  • This would allow the library to respect and support package & namespace resolutions. Like TypeScript in VS Code!
  • Related issue: [icebox] Implement trie matching for "Go To Definition" vsce-toolroom/vscode-textmate-languageservice#17

@dklilley
Copy link
Member

dklilley commented May 9, 2023

Thank you for raising this suggestion! This is a feature we want to add, and is already being developed (http://mathworks/MATLAB-language-server#1)!

@dklilley
Copy link
Member

Outline support should now be present, and will be released as an update to the extension soon. As noted in #8 , the outline currently does not display section titles. If there are any other features which you feel are missing in the outline, please feel free to open another issue.

Thanks!

@apjanke
Copy link
Author

apjanke commented May 31, 2023

Yay! I'll testi it out over the weekend if it makes it to the VS Code Marketplace by then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants