-
Notifications
You must be signed in to change notification settings - Fork 64
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
Enable initial support for completions #185
Conversation
I think it is a good design decision to keep the completion code separate from the parsing code. They will have different goals and it will be complex to try to share code and it will not provide a benefit. As you write the user benefits from the completion to be aware of the context where it is triggered. The challenging part is to make the completion more and more context aware. |
I took a first look at the code. The code looks nice overall. The only thing I did not like was the hardcoded positions in the test case. This is something I have really wanted to avoid as it maskes reviewing, changing and debugging test cases very tiresome. A more high level comment is if it is premature to enable completions of keywords such as "loop" etc. I think where the server can really improve the completion is that it actually knows which libraries, design units and functions are defined. |
I guess a good starting point here is to somehow store some more analysis results to have them for later analysis. At the moment, if I'm not wrong, a
I will change that, thanks for the feedback!
I can remove the bare word completions for now. In future, however, it might be beneficial to remove the snippets from the VSCode extension and put them into the server. The server should be able to provide the same capabilities and the completions can be a bit more context aware. At the moment, for example, the |
# Conflicts: # vhdl_ls/src/stdio_server.rs
Yes the What is really needed for completion is a list of symbols annotated by the interval in the source file where they are visible. Such data could maybe be generated in parallel with the scope. Alternatively an AST traversal could be done when a completion was triggered. The AST would be traversed until the point of completion and all visible symbols recorded. For performance reasons it is probably better to do extra work at the time of completion rather than creating a completion specific data-structure during every analysis. Re-analysis will happen every time the user types but completion will happen much more seldom. Thus I would initially prefer to do a search of the AST to re-create the scope at the completion point. Another issue with completing names in scope is that the source file must not be "broken". When the user is typing something and trigger completion it is often results in an illegal VHDL file because they only partially typed a function signature. It is then important that the parser can recover and skip the broken part to finish the analysis of the file. Otherwise there will be no symbols since VHDL LS stopped processing the file.
Yes the goal should be to remove the snippets from the client and ship them with the server. Then all clients will behave the same. Until that point it makes no sense to add bare word completions. |
I have no further comment. I tried it locally in vscode and it offers me use-clause completions. Is this ready to be merged for your side? |
I'll add 2-3 unit tests, just for regression (I noticed I had nothing for the actual completion). But then it should be good to go |
Okay I added the tests. I had to be a bit creative (can't use |
With this PR I want to lay the groundwork / discuss possible implementations for completions.
This PR enables the following two basic completions:
gives the user the choice of all currently selected libraries and
gives the user the choice of all primary units starting with
st
(such asstd_logic_1164
,std_logic_arith
, ...)While the current implementation works, it is fundamentally based on pattern matching. A token-stream is generated until the position of the cursor. Based on the last couple of input parameters, suggestions for the following parameter is given.
This approach works quite well for simple examples but it has the caveat that logic needs to be duplicated. The parser already expects certain values and the logic embedded in the parser could potentially be reused. However, I did not find a way to use what's already implemented in a meaningful way without rewriting a lot of code. If there is another approach I'm happy to discuss / implement that. For now, I think that this approach might be a good start.
Edit: Also contains initial support for "regions" to make completions more focused. I.e. in declarative regions other completions should be triggered compared to sequential regions or others. Nested regions are also supported
Example:
Should trigger completions for
library
,use
,entity
, ...while
should trigger completions for declarative items, i.e.
signal
,constant
, e.t.c.