-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Make Pygments to work correctly with QSyntaxHighlighter #3491
Conversation
Note to self: This could work for task 2: https://wiki.qt.io/Delay_action_to_wait_for_user_interaction |
Also see this for how much to wait to decide if a user has stopped typing: |
This work was done by @randyheydon in https://bitbucket.org/spyder-ide/spyderlib/pull-requests/103 and now we're moving it to GitHub
a62dcb2
to
6f3b385
Compare
@ccordoba12 could you provide some context on the description? |
@goanpeca, sorry for being so brief :-) I updated the description to be more informative. |
Thanks for carrying this on @ccordoba12. I don't think I'll have a chance to help with this, but I would like to make a quick note. The best way to fix this, I think, would be to change Pygments to support incremental lexing. In the past, I believed they would not accept such a change, since it's outside of their scope. However, I've since noticed that they have the same problem with the I haven't looked into it too much, but I imagine this would be done with a new or modified method that takes the current lexer state as an argument, and includes the final lexer state as part of the returned data. That way, you could parse a line based on previous state, highlight that line, then parse the next line with the new state. Some of the individual language parsers would also need to be modified so that they split multi-line constructs into shorter constructs with intermediate states. |
@ccordoba12 what is the status of this? I could add the generic threaded worker from the work I will add for the |
@goanpeca Regarding this "generic threaded worker" you are working on, does the worker run on a different thread in the same process, or a different process? I'm asking because for the unittest plugin, I need a worker in a different process which can continuously communicate the results back to spyder, so that the display can be updated in real time instead of having to wait until all tests are run. |
@jitseniesen yes, I will have a generic worker for running python stuff (a method/func? that may be a long process) and a specific set of workers for a couple of tasks. A QProcess worker (that effectively runs a separate process and periodically signals (worker, stdout, stderr) so you can use it as well. I will add this code as generic stuff on spyder so any plugin can use this workers for long running processes. |
Excellent, I'll wait for it to appear so that I can use it instead of making my own. Perhaps we can also make the introspection stuff use your generic worker. |
We are planning on using https://github.com/Microsoft/language-server-protocol, which already provides a generic framework for what we need, plus there is already a python implementation plus many other languages, so we would get completion, linting for free for all those languages |
self._is_finished = True | ||
|
||
|
||
class ProcessWorker(QObject): |
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.
@jitseniesen this is the idea for the process worker, maybe you could take a look and see if it fits your needs.
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.
@goanpeca Yes, I think that will work for me.
@goanpeca, how is this going? We need to merge this one as soon as we can, please. |
spyder/utils/syntaxhighlighters.py
Outdated
@@ -1074,33 +1075,81 @@ def __init__(self, parent, font=None, color_scheme=None): | |||
# Load Pygments' Lexer | |||
if self._lang_name is not None: | |||
self._lexer = get_lexer_by_name(self._lang_name) | |||
|
|||
|
|||
|
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.
Remove two blanks here and just leave one.
spyder/utils/syntaxhighlighters.py
Outdated
self._allow_highlight = True | ||
|
||
def make_charlist(self): | ||
"""""" |
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.
Missing docstring.
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.
Fixing!
spyder/utils/syntaxhighlighters.py
Outdated
|
||
def make_charlist(self): | ||
"""""" | ||
def test_output(worker, output, error): |
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.
Why is this function called test_output
? It would seem to imply that it's only used for tests.
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.
Fixing!
# Highlight using Pygments highlighter timer | ||
self.timer_syntax_highlight = QTimer(self) | ||
self.timer_syntax_highlight.setSingleShot(True) | ||
self.timer_syntax_highlight.setInterval(300) |
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.
Please add a comment to explain this 300
here.
spyder/utils/syntaxhighlighters.py
Outdated
@@ -1052,6 +1052,7 @@ class PygmentsSH(BaseSH): | |||
# Store the language name and a ref to the lexer | |||
_lang_name = None | |||
_lexer = None | |||
_charlist = [] |
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.
This doesn't seem to be needed because _charlist
is also initialized in __init__
below.
spyder/utils/syntaxhighlighters.py
Outdated
# parsing | ||
self._worker_manager = WorkerManager() | ||
|
||
# Store the format for all the tokens after pygments parsing |
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.
pygments
-> Pygments
spyder/utils/syntaxhighlighters.py
Outdated
self._charlist = [] | ||
|
||
# Flag variable to avoid unnecessary highlights if the worker has not | ||
# yet finish processing |
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.
finish
-> finished
@goanpeca, do you want me to finish this one? |
Oops I did not see the comments, giv me a sec @ccordoba12 done! |
Thanks a lot for helping me to finish this one @goanpeca!! Great work! |
Fixes #2122 * Conflicts: - spyder/utils/syntaxhighlighters.py
Fixes #2122
Context:
TODO: