Open ntluong95 opened 5 months ago
Thanks for logging this, this is as a result of the token types from of the Jedi-based language server in use in Positron's Python LSP.
Is there anyway to use Pylang, which is much better?
@ntluong95 I can't find any info on a "Pylang" syntax highlighter. Do you mean Pylance?
Yes sorry I meant Pylance. Fortunately I found this one, which serve my need. Maybe something you can consider to integrate into Positron as I know Pylance is only for VSCode. Link: https://open-vsx.org/extension/detachhead/basedpyright
Yes sorry I meant Pylance. Fortunately I found this one, which serve my need. Maybe something you can consider to integrate into Positron as I know Pylance is only for VSCode. Link: https://open-vsx.org/extension/detachhead/basedpyright
Here is the result after installing the package. However, the Quarto
file could not display syntax highlighting for Python module. I think Positron should have more support for Quarto
extension since now the Jupyter Notebook is far more better
Thank you for pointing out basedpyright, we'll look into it!
Aside from the Quarto issue you mentioned, how well does basedpyright currently work in Positron? At the very least, we may be able to iron some of those issues so that users can choose alternative language servers – although it is worth noting that completions would no longer be aware of your session's variables and would not benefit from other Positron-specific language server features in future.
It works well, excepted that in the Outlines, you will see 2 language servers. I think if you can look at their code and cherry-pick the part that help to recognize Python module keywords, and also attach it to Quarto, the problem will be solved. Just my naive idea
Could you please share a screenshot of the 2 language servers in Outlines?
Attached is the screenshot
But is there any plan to support display syntax highlighting of Python code for Quarto too?
We do have syntax highlighting for Python code in Quarto, yes:
Is there a specific syntax highlighting feature you are missing or problem you are observing?
Currently, module keywords such as pandas, pd, etc. are not highlighted. See the example below
In Vscode
In Positron
I think module keywords, and semantic highlighting from Pylance is missing. That's why I open this thread
Found an interesting extension that can improve the situation although it is not the sustainable solution: Settings:
"highlight.regexes": {
"(\\bimport\\s+(?:\\w+(?:\\.\\w+)*(?:\\s*,\\s*)?)+|\\bfrom\\s+\\w+(?:\\.\\w+)*\\s+import\\s+(?:\\w+(?:\\s*,\\s*)?)+|\\bas\\s+\\w+)": {
"regexFlags": "g",
"filterLanguageRegex": ".*",
"filterFileRegex": "\\.qmd$",
"decorations": [
{ "color": "#e5c07b" }
]
},
"(?<!\\bself\\.)(\\b\\w+\\b(?=\\.(?:\\w+\\s*\\())|(?<=\\bfrom\\s+)[\\w.]+(?=\\s+import))": {
"regexFlags": "g",
"filterLanguageRegex": ".*",
"filterFileRegex": "\\.qmd$",
"decorations": [
{ "color": "#e5c07b" }
]
},
"(#\\|.*)": { // This regex matches comments starting with #|
"regexFlags": "g", // Global flag to match all instances
"filterLanguageRegex": ".*", // Apply to all languages
"filterFileRegex": ".*", // Apply to all files
"decorations": [ // Decoration options to apply to the capturing groups
{ "color": "#b38c31" } // Decoration options to apply to the entire comment starting with #|
]
}
}
"editor.tokenColorCustomizations": {
"textMateRules": [
{"scope": ["meta.embedded.block.python"],
"settings": {"foreground": "#e06c75"}},
{"scope": ["variable.parameter.function-call.python"],
"settings": {"foreground": "#b0dddb"}},
{"scope": ["meta.attribute.python"],
"settings": {"foreground": "#85c0df", "fontStyle": "italic bold"}},
{"scope": ["variable.parameter.function.language.python"],
"settings": {"foreground": "#85c0df", "fontStyle": "italic bold"}} ,
{"scope": ["constant.other.caps.python"],
"settings": {"foreground": "#4fc1ff"}}
]}
Output:
+1 for this change. Tried to switch from VScode but too much of my python code has no syntax highlighting
The ruff team is "considering" semantic highlighting "but not in the near future" (see https://github.com/astral-sh/ruff-vscode/issues/438#issuecomment-2033721488). Tracking issue: https://github.com/astral-sh/ruff-lsp/issues/237
+1 for this change. Tried to switch from VScode but too much of my python code has no syntax highlighting
Same here. Are there any news? It's such a pity to drop Positron because of this.
Unfortunately this isn't a priority at the moment, but I did spend a little time seeing what it would take to support semantic highlighting with Jedi on the 3731-investigate-jedi-lsp-semantic-tokens branch if anyone is interested in pursuing this further.
That should get basic semantic highlighting. From my understanding, it's easy with Jedi to classify declarations (e.g. in def f(): pass
, f
is a declaration of a function). The trickier part will be correctly classifying references (e.g. calling f
later in your code), especially references to objects in larger external modules. I think the correct Jedi API is infer()
which might be too slow for the semantic highlighting usecase.
The language server protocol also supports updating semantic tokens given edits to the document (rather than starting from scratch each time). I haven't looked into whether that's necessary (or possible) with Jedi. Looking at this comment, Jedi's parser parso
heavily utilizes caching of different parts of the document for performance, so it might not be necessary to support semantic token edits.
It would be helpful to know from you all which token types are the most important, and we can look into the feasibility of getting that to work with Jedi.
I don't have the knowledge on this, but this document might be helpful to know all of the token type.
For prioritizing purpose, for me at least module keywords, class methods, function parameters, This one is not so good, but have some key takeaways that we can start from I hope
@seeM how is the progress. I think Jedi is quite good in general but hope Positron can implement something like customized Jedi like Microsoft did with Pylance, which improve a lot of UX
I tested and it works quite well. May be add also "variable.declaration", "property.declaration" and "function.builtin". Those are something I have set syntax highlighting when using Pylance.
The problem is it doesn't work on Jupyter notebook. But Pylance doesn't work on Quarto document. I think the current highlighting is good enough for me at least to move forward, as long as Jupyter Notebook and Quarto document support for it, I may not need Pylance. I can use Ruff for type checking and linting
Currently, module keywords such as pandas, pd, etc. are not highlighted. See the example below
In Vscode
In Positron