-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: python language features #991
base: main
Are you sure you want to change the base?
Conversation
@scnwwu In main branch, formatting the above test code, the code disappearing problem occurs again just like before. Would you mind to have a check again? :) |
@jingjiajie, I have raised the issue #992 to track the changes. Thanks. |
@jingjiajie, I failed to build your PR code on my PC. |
Fixed |
There's a UX problem with this PR. The context menu item "Go to Definition", "Go to Declaration" etc. now always display. For most SAS code except PROC PYTHON, they have no functionality. It may be confusing for some user who rarely use Python. |
Got unexpected
Got unexpected
|
It does NOT work in browser build. |
@scnwwu It's controlled by the InitializeResult returned by onInitialize() at server side. I'm not sure if there's a way to dynamically control this. Could have a future investigation. Please let me know if you have more ideas about this design.
I found Microsoft maintained two language servers for Python, one is for desktop(Pyright https://github.com/microsoft/pyright), another is for browser(https://github.com/microsoft/vscode-python). In this PR we integrated the Pyright, so the browser version will become another work after this. |
Would you take a look at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#client_registerCapability |
Good. It seems to work! |
@scnwwu I found they are caused by Lexer.startFrom(). The CodeZoneManager reads token by calling the Lexer.startFrom() in the middle of embedded code. Without having read "proc python" in previous lines, the Lexer can't regard the token as a part of embedded code, instead it regards it as a regular proc stmt, then gives wrong result. For example, the correct token should be 'print("x = " + x)' because it's in a proc python block, but if use Lexer.startFrom() from the start position of this line, the token returned is "print", that's wrong. Is it possible to remove all the occurance of Lexer.startFrom() function, instead use SyntaxProvider.getSyntax()? It returns correct tokens. However it seems to be a big complexity, I'll need your confirmation. |
@jingjiajie, please reset context in |
All reported issues so far have been fixed. |
@jingjiajie, the build is hang. Would you please address it? |
c88174f
to
89cc1dd
Compare
New reported bugs are all fixed. @Zhirong2022 @tianliang657 |
The typed python code will be removed in the code below after format code
|
@scnwwu I haven't read through the formatter codes. But just found a logic that is suspicious: |
@jingjiajie, the embedded code is handled separately. Would you please try add |
j = i - 1; | ||
type = syntax[j].style; | ||
|
||
for (let i = 0; i < syntax.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jingjiajie, would you please provide a detailed explanation for this change? It looks like a fundamental logic. I'd like to verify it carefully. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember this change is to fix the bug:
There is no autocomplete if the first line is a comment. Try to type 'python' or 'print' next to 'proc'
/* */
proc
Because if the starting one token of the whole document is a comment, _token() returned a null value. This change is to fix this bug.
The intention is only to fix that issue, and the remaining logics should keep the same behavior as before.
Error 'Request textDocument/foldingRange failed.' if trying to delete 'endsubmit' at line 6.
|
@scnwwu Sorry for missed message, I just see your reply. I tried replace i with interactive, then it worked. I found the root cause in the code, and added support for "i" keyword in addition to interactive; Thanks. |
Fixed. |
@Zhirong2022 In this case, the first python code line is print('test'), but actually we will insert a hidden if True: line before this line, that is, the same line of submit; clause. That's why you see it insert the import clause at the line of submit clause. Workaround 1: Workaround 2:
So that we'll not insert the hidden if True: line. The print('test') will be the first line. |
New libs are installed, please run npm install
Summary
"Pytight" language server is integrated, which is the Microsoft's official python language server.
Thanks to the Pyright, the following features are supported:
Code completion
Hover hint
Outline for python code
and functions shown in the picture:
Due to reasons, the following features are not yet included:
Python code formatting: It's not included in the Pyright language server. It has to be a feature we separately implement in the future.
Folding range for Python code: Because we set to use the Language Server side Folding range parsing rather than using the configuration file, it only recognizes the Folding ranges we returned from language server. However, the Python folding range is naturally implemented with configuration file, so it's ignored. We have to treat it as a separate feature and manually implement it with our language server in the future.
a simple test code: