Autodesk-AutoCAD / AutoLispExt

Visual Studio Code Extension for AutoCAD® AutoLISP
https://marketplace.visualstudio.com/items?itemName=Autodesk.autolispext
Apache License 2.0
83 stars 29 forks source link

Intelli Sense for functions #16

Open hansWurst-creator opened 4 years ago

hansWurst-creator commented 4 years ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] #15

Describe the solution you'd like Show in which part of the function I am and give hints what parameters are appropriate at this place. Similar to how Excel shows what Parameter in what function is currently being edited image

Example for signature in vscode C# image

JD-Howard commented 4 years ago

Now that the web help is hooked up, I am going to start work on using my "webHelpAbstraction.json" object to implement a contextual hover tool tip for symbols.

Proposal For example you would see something like the tooltip on the right of your image if you hovered your mouse over SensorImageData text.

Because of the way lisp works, I don't know if its reasonable to provide the in within-parenthesis contextual to index documentation. Think about it, everything is in a parenthesis unless you aren't using defun's. I am pretty sure (potentially) scanning the entire document every time the blink indicator moves could very easily cause performance problems. Would my hover proposal above be a sufficient compromise? I know it would be for me...

Stretch Goal I would also like to collect/display defun signatures from opened files to at least show their argument variables too.

hualin-wu-2000 commented 4 years ago

I think for contextual help it depends the lisp syntax, to avoid reinvent the wheel, maybe firstly to check this file https://github.com/Autodesk-AutoCAD/AutoLispExt/blob/main/extension/src/format/sexpression.ts#L102

>>I am pretty sure (potentially) scanning the entire document every time the blink indicator moves could very easily cause performance problems. Would my hover proposal above be a sufficient compromise? I know it would be for me.. Maybe we need to create a global cache to cache all the lisp syntax results for example the above S-expression. Maybe another option is to find the current S-expression AT the current cursor position. Maybe see this file https://github.com/Autodesk-AutoCAD/AutoLispExt/blob/main/extension/src/format/autoIndent.ts#L682

>>I would also like to collect/display defun signatures from opened files to at least show their argument variables too. I think it needs to check all the OPENED files AND all the lisp files included in the project files (.prj).

JD-Howard commented 4 years ago

It sounds like I proposed a feature that is too vastly different from what was being requested and maybe I should have generated a new enhancement since they are seemingly different things.

  1. Mouse-Hover, This has a very simple implementation that could generate a lot of usefulness to end users and would have a very minimal footprint in the code base. IE, the underlying contiguous string (using regex) either exists in one of my dictionaries or it doesn't. However, you are right, I should at least be planning for at-index help while making a simple mouse hover that is purely checking the underlying symbol. I will check to see how performance viable the findContainers(document, position2d) function is for identifying the underlying symbol is vs a simple regex.
  2. At-Index, I have been through the sexpressions and have found them to be something of a NestedNode->Children[] type object that could potentially require quite a bit of scanning. Those are excellent containers for certain things and probably the only way to get at-index contextual help popping up as a user is typing, but a substantial time investment when I still haven't fully worked out/developed the extraction of type information that a hover would help me test. I will certainly look into this next.

Maybe we need to create a global cache to cache all the lisp syntax results for example the above S-expression.

Yes, I absolutely want to see a global cache. That would by far give us maximum ability to provide truly amazing contextual feedback. That stretch goal I proposed is something I planned on looking into, but assumed it would require some form of global cache and considered it more long term.

JD-Howard commented 4 years ago

That findContainers function is definitively super nice and I tried it on a very large LSP that was all wrapped into a single defun; which seemed to have excellent performance. It is exactly what we need to keep contextual information popped up as a user types. Still not sure if it is the right thing for a mouseHover though.

If you take this expression: (strcat "running speed:" speed)

Hovering over any piece of this would return the context of strcat and I think I'd rather pop up nothing at all rather than the strcat information when the mouse isn't directly over strcat. Maybe type information, but then I think we are back to your cache that actually has speed pre-identified as a variable.

Leaning towards document.getWordRangeAtPosition with a regex for hovering and findContainers for non-mouse positional information.

hualin-wu-2000 commented 4 years ago

to create a global cache for all the S-expression in all the LSP files what are opened and included in prj project are useful, it can benefit the following VSCODE features like:

  1. more powerful auto-completion
  2. go to definition / find all references

So I agree with you to create a global cache. I think it is worth for us to take longer time to do some prototype and write a more detail wiki.

Now I don't remember that if findContainerscan get the correct information for non-complete form like: (strcat "this is a test"

JD-Howard commented 4 years ago

The hover provider has a function signature like this: public async provideHover(document: vscode.TextDocument, position: vscode.Position)

When I feed those two arguments into the findContainers, it does locate the entirety of (strcat "running speed:" speed) as its first item in the returned list; at least it does if the cursor was anywhere on that expression. The remaining returns are step by step up to the defun it lives in being the 'entire" defun statement. So, because it is returning that whole expression, I have no context of what the mouse was directly over, I would just be trimming parenthesis and taking the first segment and popping whatever (if any) context I had for that symbol.

RE: Global Cache I've been looking at how to do this (communicate with the whole workspace) and I figured out how to get a list of the files and their paths, but those are 'TextDocument" objects. The current formatters weren't really designed to work with raw text. Any suggestions on that? I looked into Language Service Providers, but honestly the documentation for those is horrible and all of my attempts to find/use entry points into such a system don't work. Maybe if the 'vscode-languageserver' and 'vscode-languageserver-textdocument' packages were added to the project I'd have more success, but not real sure because their documentation is really hard to follow and not geared towards non-tcp versions of this.