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

fix(vscode-plugin): ignore non-existent ".git" files, support untitled/unsaved files on VS Code #927

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kiding
Copy link
Contributor

@kiding kiding commented Mar 18, 2025

Issues

Fixes #487. Fixes #382.

Description

This PR restricts clientOptions.documentSelector to the file and untitled scheme, and changes load_file_dictionary to always succeed on the untitled scheme. This will prevent the non-existent .git files from showing up in Problems since they use gitfs scheme1, and make Harper work on untitled/unsaved files. HarperAddToFileDict should fail as expected.

VS Code's documentation2 suggests there may be other schemes like untitled, http, ftp, etc. Harper never worked with untitled with an error saying ERROR harper_ls::backend: Unable to generate the file dictionary. Harper's file_dict_name assumes url is a file path, so this shouldn't break any preexisting feature.

Demo

N/A

How Has This Been Tested?

To test for untitled: open a new document, type Errorz, check Output, see no error. one error saying Did you mean to spell “Errorz” this way?.
To test for .git:

mkdir test && cd test
git init
echo 'Errorz' > test.txt
git add test.txt
code .

Check Problems, see no error for test.txt.git.

Checklist

  • I have performed a self-review of my own code
  • I have added tests to cover my changes

Footnotes

  1. https://github.com/microsoft/vscode/pull/86674

  2. https://code.visualstudio.com/api/references/document-selector

Copy link
Collaborator

@mcecode mcecode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this issue! LGTM, just a few nitpicks.

@mcecode
Copy link
Collaborator

mcecode commented Mar 18, 2025

Just to note, if this is merged, we may also want to close #382 as not planned or won't fix since this would stop the VS Code extension from sending untitled files to harper-ls, which would prevent "Unable to generate the file dictionary." errors from occurring when opening untitled files but also will stop us from being able to support them going forward.

@kiding
Copy link
Contributor Author

kiding commented Mar 18, 2025

Done! Thank you.

@kiding kiding changed the title fix(vscode-plugin): restrict document scheme to file, ignore non-existent ".git" files fix(vscode-plugin): ignore non-existent ".git" files, support untitled/unsaved files on VS Code Mar 18, 2025
@kiding
Copy link
Contributor Author

kiding commented Mar 18, 2025

@mcecode Decided to add the untitled support as well. load_file_dictionary returns an empty one when it encounters the untitled scheme; same behavior as there is no file dictionary for a given file. HarperAddToFileDict and save_file_dictionary would fail as expected.

@elijah-potter
Copy link
Collaborator

@kiding, does that mean unsaved documents (i.e. blank buffers that aren't on-disk) will now work for text editors other than VS Code?

@mcecode
Copy link
Collaborator

mcecode commented Mar 19, 2025

does that mean unsaved documents (i.e. blank buffers that aren't on-disk) will now work for text editors other than VS Code?

Only if they support the same URI scheme that VS Code uses which is "untitled".

Copy link
Collaborator

@mcecode mcecode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kiding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants