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

Allow configuring targeted file extensions #38

Merged
merged 6 commits into from
May 28, 2024
Merged

Conversation

InSyncWithFoo
Copy link
Owner

Fixes #35.

Copy link

github-actions bot commented May 9, 2024

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2024.1.3
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@bzoracler
Copy link

bzoracler commented May 9, 2024

This works well, thank you! I checked this on Windows 11 and Pop OS! 22.04.

image

For Python users especially, this means you can now check .pyi and .pyw files with Pyright LS. .pyi checking itself was missing from IntelliJ.


A few quirks:

  • The LS only turns on upon activating a .py window in the IDE. If you were only working with non-.py files, the LS won't turn on until you open a .py file:

    • Before (fresh start of IDE):

      image

    • After opening bad.py:

      image

  • The mojo file extension 🔥 is not preserved between IDE sessions:

    • Before exiting the IDE:
      image
    • After exiting the IDE and restarting:
      image
    • Such extensions are exceedingly rare, and mojo itself provides its own LSP. I don't think this is a big issue.

@bzoracler
Copy link

  • The mojo file extension 🔥 is not preserved between IDE sessions:

    • Before exiting the IDE:
      image
    • After exiting the IDE and restarting:
      image
    • Such extensions are exceedingly rare, and mojo itself provides its own LSP. I don't think this is a big issue.

I just realised that a blank extension (e.g. in py|pyi||pyw) is misleading, because IntelliJ can recognise files with no extensions as an appropriate file based on the presence of a shebang (automatically associating e.g. #!usr/bin/python as a Python file). From https://www.jetbrains.com/help/idea/creating-and-registering-file-types.html#register-new-association:

Open matching files as text and auto-detect file type by content: open the file without an extension as a text file and identify its type by the content, for example, by the shebang line.

If support for non-standard/blank file extensions is out-of-scope, it might be worth to just ban blank extensions and non-text extensions.

Copy link

github-actions bot commented May 9, 2024

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2024.1.4
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@InSyncWithFoo
Copy link
Owner Author

InSyncWithFoo commented May 9, 2024

I think all extensions should be treated equally, including empty and emojis. As for "🔥" (U+1F525 Fire), it seems that PyCharm couldn't serialize it while writing to the pyright.xml file. I have posted a question asking about this on Slack.

@InSyncWithFoo
Copy link
Owner Author

The LS only turns on upon activating a .py window in the IDE. If you were only working with non-.py files, the LS won't turn on until you open a .py file [...]

I think this was because I forgot to change this line in PyrightLSSupportProvider.kt:

The latest commit should fix it.

@bzoracler
Copy link

bzoracler commented May 13, 2024

5f931ff

I couldn't get the LS to scan files for empty file extensions by specifying Target file extensions. I've tried

  1. Specifying nothing
  2. Specifying || (which strips to nothing upon exiting and re-entering the settings dialogue)
  3. py||pyw

In case this matters, the file I tested is named noext, and the contents are:

#!usr/bin/python
n: int = ""
b: str = []

I've also tried adding the relative and full path of the file to pyrightconfig.json's include field, both linux-style and Windows-style path separators. No luck.

Unfortunately this was tested on Windows, which doesn't recognise shebangs. However, I don't think this should matter, as PyCharm recognises this as a Python file (the Python icon shows up).


I think this was because I forgot to change this line in PyrightLSSupportProvider.kt:

The latest commit should fix it.

Thank you, this worked.

@bzoracler
Copy link

5f931ff

Just a guess - maybe this is an issue with pyright itself? Does the LS recognise files with no extensions, or can it differentiate between directories and files-with-no-extension in pyrightconfig.json? microsoft/pyright#5441 suggests that it is fixed "for the CLI", but I'm not sure if this includes the Pyright language server CLI.

@InSyncWithFoo
Copy link
Owner Author

I couldn't get the LS to scan files for empty file extensions by specifying Target file extensions. I've tried

  1. Specifying nothing

Huh, I didn't think of that. Maybe it should be made a separate checkbox then.

Copy link

github-actions bot commented May 28, 2024

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2024.1.5
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@InSyncWithFoo
Copy link
Owner Author

After much consideration, I have decided to merge this without supporting either empty or emojis. These limitations will be documented accordingly.

I have a hunch that this is not a very good decision, but whatever.

@InSyncWithFoo InSyncWithFoo merged commit d5c69db into master May 28, 2024
9 checks passed
@InSyncWithFoo InSyncWithFoo deleted the issue-35 branch May 28, 2024 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to recognise file extensions other than .py and .pyi?
2 participants