Skip to content
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

MEGA-ISSUE: Syntax highlighting in language-python #880

Open
savetheclocktower opened this issue Jan 19, 2024 · 18 comments
Open

MEGA-ISSUE: Syntax highlighting in language-python #880

savetheclocktower opened this issue Jan 19, 2024 · 18 comments
Labels
bug Something isn't working

Comments

@savetheclocktower
Copy link
Contributor

savetheclocktower commented Jan 19, 2024

IMPORTANT: Some issues have already been fixed!

If you’re still on the regular 1.113 release, you might be suffering from a problem that has already been fixed. Many fixes landed on master in #859. You are encouraged to download the latest rolling release — both (a) to see whether what you’re reporting has been fixed, and (b) so that you can enjoy the fixes that have been reported since the 1.113 release.


This will serve as a catch-all issue for any problems you may encounter with syntax highlighting in REPLACE files (language-python). If you have problems with the new syntax highlighting (or folds, or indents) that are specific to .py files, keep reading.

Something isn't highlighting correctly!

If you’ve found any highlighting regressions since 1.113:

First, please scroll down and see if someone else has reported the issue. If so, then you need only sit back and wait for a fix — most issues will be fixed in version 1.114!

If not, please comment with

  • A small amount of sample code to reproduce the issue
  • Screenshots (before and after would be ideal, but just the “after” is OK for obvious things

I want to go back to the old highlighting!

You can easily opt out of the new Tree-sitter highlighting for any language, but first please:

  • subscribe to this issue so you'll know when the problem is fixed
  • remove the config change when the next release comes out so that you can enjoy the new grammar once again

To revert to the old Tree-sitter grammar for this language only, add the following to your config.cson:

".python.source":
  core:
    useLegacyTreeSitter: true

To revert to the TextMate-style grammar for this language only, add the following to your config.cson:

".python.source":
  core:
    useTreeSitterParsers: false
@savetheclocktower savetheclocktower added the bug Something isn't working label Jan 19, 2024
@matbme
Copy link

matbme commented Jan 19, 2024

Python parser also seems to be out-of-date. The .wasm in language-python package is from 10 months ago, and the tree-sitter-python repo has seen a couple of updates since then.

The not in inside an if statement also doesn't get properly highlighted.
Example:

if tag not in self.all_steps:
    self.all_steps[tag] = 0

Inspector:

if_statement
  condition: comparison_operator
    identifier
    attribute
      object: identifier
      attribute: identifier

@savetheclocktower
Copy link
Contributor Author

Awesome, thanks. I'll update to the latest tree-sitter-python today and get these fixes in.

@matbme
Copy link

matbme commented Jan 19, 2024

break statement also isn't highlighted. Probably missing definition in highlighs.scm, should be alongside continue, which is marked as @keyword.control.repeat._TYPE_.python

@savetheclocktower
Copy link
Contributor Author

OK, updated to latest tree-sitter-python and applied those fixes. Here's the commit. Thanks! Let me know if you find anything else.

@asiloisad
Copy link
Contributor

asiloisad commented Feb 28, 2024

The modern tree-sitter auto-indent is broken if multiple cursors are used. Tested in safe mode.

  1. a state before
    image
  2. press Enter
  3. state after
    a) legacy tree-sitter
    image
    b) modern tree-sitter
    image

@Askaholic
Copy link

Hello! I'm a long time user of Atom and have been following the pulsar blog for a while. Love to see the amount of work that folks are still putting into this editor! With the release of the modern treesitter implementation I decided to see if it was finally time to start migrating over from my Atom install.

There are a few things that I noticed right off the bat which I'm not necessarily sure are bugs but that nevertheless stood out to me.

  1. Variables in assignment statements are colored red. This is confusing to me as I'm used to all occurrences of a variable having the same color. Maybe it's just a matter of getting used to, but it also seems odd to me that special python variables like __file__ and __name__ also get this same color.

  2. Code folds on brackets don't show the closing bracket. In atom if you fold on a dictionary or list as shown below, it will render as {...} or [...], however it seems with modern treesitter the closing bracket is dropped {... or [....

Anyway, thanks for all the hard work keeping this editor going!

$ pulsar --version
Pulsar  : 1.114.0
Electron: 12.2.3
Chrome  : 89.0.4389.128
Node    : 14.16.0

Modern Treesitter

image

Folds

image

Legacy Treesitter

image

Folds

image

@savetheclocktower
Copy link
Contributor Author

@Askaholic thanks so much for the detailed feedback! Item 1 is an intentional design decision (which I can elaborate on when I get a chance), and item 2 is unintentional (and therefore a bug).

I'd encourage you to give it a week or so to see if you get used to the variable highlighting differences… but if you still hate them then, we can tell you how to use your user stylesheet to get the old highlighting behavior back. Meanwhile, I'll investigate the issue with folds.

Thanks for the report!

@Askaholic
Copy link

Here's another issue I noticed with the indentation hinting. It doesn't seem to get class attributes with annotations correct:

Before:
image

After:
image

I would expect the cursor to be one level of indentation back from where it is.

Here are other examples that I've tried which have the same result:

class Foo:
    field1: int = 10
class Foo:
    field1: int = 10,
class Foo:
    field1: list[int]

However, these work correctly:

class Foo:
    field1
class Foo:
    field1,
class Foo:
    field1 = 10

@savetheclocktower
Copy link
Contributor Author

That was dumb of me for assuming that every occurrence of a colon was a hint that the next line should be indented — which I think would be true if not for type annotations. I can update it to enforce that the colon has to occur at the end of the line.

@savetheclocktower
Copy link
Contributor Author

That was dumb of me for assuming that every occurrence of a colon was a hint that the next line should be indented — which I think would be true if not for type annotations. I can update it to enforce that the colon has to occur at the end of the line.

Almost forgot about this one, but got it into #968. Thanks for the report, @Askaholic!

@asiloisad
Copy link
Contributor

asiloisad commented Apr 12, 2024

If first two characters are upper cased, then element has support.other.function.python class instead of support.type.constructor.python.
image

@savetheclocktower
Copy link
Contributor Author

If first two characters are upper cased, then element has support.other.function.python class instead of support.type.constructor.python. image

Easy fix; added to #968. Thanks!

@Askaholic
Copy link

Hey, I've been using pulsar for the last few months and its been working great for me! However, I noticed that the visual issue with folds that I described here is still happening on pulsar 1.118.

Thanks for continuing to work on this project!

@savetheclocktower
Copy link
Contributor Author

Hey, I've been using pulsar for the last few months and its been working great for me! However, I noticed that the visual issue with folds that I described here is still happening on pulsar 1.118.

Thanks for continuing to work on this project!

I should've at least given you the workaround for your first issue (variable assignments not sharing a color with variable usage). You can add this to your user stylesheet:

@import "syntax-variables"; // (this line may already be present)

.syntax--source.syntax--python .syntax--variable {
  color: @syntax-text-color;
}

As for the other issue: it slipped through the cracks, I'm afraid. I'll take a look today and make sure that a fix gets made for 1.119. Thanks for the reminder!

@savetheclocktower
Copy link
Contributor Author

2. Code folds on brackets don't show the closing bracket. In atom if you fold on a dictionary or list as shown below, it will render as {...} or [...], however it seems with modern treesitter the closing bracket is dropped {... or [....

This is finally fixed in this commit. #1028 should land just before the 1.119 release in mid-July. Thanks for your patience!

@asiloisad
Copy link
Contributor

asiloisad commented Oct 20, 2024

There is a problem with links if string is more than link. Pulsar v1.122.0

image

@savetheclocktower
Copy link
Contributor Author

There is a problem with links if string is more than link. Pulsar v1.122.0

Seems like a problem with my tree-sitter-hyperlink parser. I'll take a look. Thanks!

@savetheclocktower
Copy link
Contributor Author

@asiloisad, this is fixed in #1118 and will go out next month. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants