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

Use a text document's language_id instead of file extensions #434

Merged
merged 4 commits into from
Jul 31, 2022

Conversation

alcarney
Copy link
Member

As noted in #425, relying on a file's extension to determine whether its contents is a reStructuredText document or not is unreliable. Instead this switches the server over to checking the document's language_id when it's available, but keeping the file extension checks as a fallback.

When identifying where a given position is (python vs rst vs docstring)
use the document's `lanuage_id` field where possible. This handles
situations where a user has configured `*.txt` files in VSCode to be
treated as rst files.

If the document's language id is not available, then we fall back to
using file extensions as we did previously
The check for whether we should parse a document in
`get_initial_doctree` now relies on `get_location_type` rather than
checking the file extension. This means that files that don't have the
traditional `*.rst` extension but are treated by the client as
reStructuredText documents should now work as expected.

Additionally, by reading the document's source from the `Document`
maintained by `pygls` rather than reading from disk, document symbol
requests are more accurate taking into account any unsaved changes in
the user's editor.

This also removes the need for direct file system access - poentially
opening the door for running the vanilla docutils server in Pyodide?!
While the `language_id` patch is still unreleased and that we're still
supporting Python 3.6 (for now) this backports the functionality into
esbonio directly.
@alcarney alcarney merged commit cde4949 into swyddfa:develop Jul 31, 2022
@alcarney alcarney deleted the langid branch July 31, 2022 18:33
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.

1 participant