-
Notifications
You must be signed in to change notification settings - Fork 14
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
Where-Used Search #429
Comments
Adding @DavidFeldhoff since AL Code Actions already has some basic 'where-used' for table triggers. https://github.com/DavidFeldhoff/al-codeactions#references-to-built-in-functions |
Yes, exactly.. @anzwdev maybe we can have a chat about it? I added locally already something else and would like to talk with you about it |
Yes, we can have a chat. I have a plan how to write this functionality, it probably won't be very complex, but it will require recompilation of the base app and other symbols, so I am afraid that it will take a few seconds to get the results and memory consumption might be a bit high. |
Do you know what MS use for the Find All References feature? (or just to display the references number in the codelens) I've been thinking about some rules/actions I'd like to play around with, I've created a rough script which removes all Obsoleted symbols up to a given version. Is there a function in the DLLs that can just give me all SyntaxNode's that reference the current SyntaxNode I have? |
We're using a (custom) code analyzer rule (implemented in C#) which detects which internal procedures and which public/internal procedures from internal objects are unused/not referenced. Maybe that could help for also making a code action out of it? That's what you would like to do if I understand correctly? |
Yes, I was looking at the I've been using SyntaxTree.ParseObjectText (as described here) but I was only feeding it text content from a single file at a time and removing syntax nodes and saving the modified text back to the file, so I haven't really worked with a whole "project" (multiple files in a path). The benefit was I only needed the MS DLLs, so I could run it standalone and even parallelized, without vscode. I'm just unsure where/how I can have a service which contains the full syntax tree of a workspace and ask it for references (my case only needs to know if it has references in the first place). Similar to things like SyntaxNode.DescendantNodes / SyntaxNode.FirstAncestorOrSelf / SyntaxNode.IsKind(Kind.MemberAttribute) / ObjectCompilationUnitSyntax.RemoveNodes, Is Microsoft.Dynamics.Nav.CodeAnalysis.Workspaces.FindReferences.FindReferencesService.FindReferencedSymbolsAsync maybe the key? I haven't used the Workspaces namespace yet. I also wanted to make sure there wasn't someone else out there doing the same work at the same time, so if there's a rule coming to LinterCop / AZ then I could just wait (or help, if there's a PR for review or if it needs testing on a large solution). In the end I'd like to use the Codecop rules for unused symbols in vscode and pipelines and it also needs the code-actions especially when projects want to be able to turn the rule on for the first time. |
Hi There is no documentation for AL compiler, but it is based on Roslyn, so you can read that documentation if you want to understand how it works. What you need to solve your problem is SemanticModel. This model is created by compiling all solution syntax trees and allows to get information about data types of your syntax tree nodes. Code analyzers also have access to the SemanticModel for more complex rules that require knowledge about data types of processed nodes. To create SemanticModel of your solution, you have to use Compilation class to compile all your syntax trees and then ask it for the model. Here is the c# Roslyn documentation mentioning SemanticModel |
Thanks, I think I kind of get the idea, this repo is a great resource as well: Line 374 in 996a8ea
I have once interacted with AZ Dev Tools via custom vscode extension while attending a workshop, but I had such a short time to dig any deeper, and it was on TS-level instead of .NET. For the case of looking for unused local/internal procedures and the action of removing them, I'd prefer contributing directly to al-code-outline/LinterCop or at least help testing it if either or both parts are already implemented. |
It might be nice to have a "Where-Used Search" feature that can tell us, 'where possible', where object/variable/procedure/symbol X is used across all project symbols.
So, taking it a step further than the "Find all references" command in VSCode when you are in
.al
files, instead searching for usages/references across all symbols in the workspace/project.It might be nice if it could open an overview where you can see all references that were found (maybe similar to what you implemented for the duplicate code search and warning directives search).
I am not sure if Microsoft is working on something for this (in their AL Browser/GUI/... you name it :)), but I do not believe they are.
I do think it is quite a time investment, but I do think this might be very useful. It's been quite some times that I would really like to get some insights into where some object/symbol is used across all symbols, when I don't have the .al source files (N.B. not saying I do not have the source code, but for the "Base Application" I typically only have the .app symbol files and not a project with the .al source files :))
The text was updated successfully, but these errors were encountered: