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

helix-lsp-types: Replace url::Url type with String wrapper #11889

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

the-mikedavis
Copy link
Member

This replaces the use of the url::Url type with a newtype wrapper around a String. Changing URL type was the original motivation of vendoring/forking the lsp_types crate in #11355. The url crate is based on the WHATWG spec for URLs which conflicts with the spec that LSP requires - RFC3986. This change uses the RFC3986 reserved characters for encoding paths which should fix some issues like #11888. The parsing and interpretation of the URL as a path is then covered by Url::try_from which we use ubiquitously since #11486.

Fixes #11888

@the-mikedavis the-mikedavis added C-enhancement Category: Improvements A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer. labels Oct 14, 2024
@the-mikedavis the-mikedavis force-pushed the string-lsp-url branch 2 times, most recently from fd24a19 to 57a18e2 Compare October 14, 2024 23:25
@the-mikedavis the-mikedavis marked this pull request as draft October 14, 2024 23:35
@ryanabx
Copy link

ryanabx commented Oct 24, 2024

Hi, correct me if I'm wrong, but RFC3986 defines URIs, why are we using a URL crate for lsp URIs? I think that contributes to issues such as #11334 .

EDIT: maybe this is what this PR fixes?

@the-mikedavis
Copy link
Member Author

Exactly - this PR is working towards removing the url crate as a dependency and representing the URIs from language servers with a regular String instead.

the-mikedavis added a commit that referenced this pull request Dec 17, 2024
This is a cosmetic change to replace all direct `use`s of the `url::Url`
type in the `helix-lsp-types` crate with `use crate::Url;`. The types
are the same type currently: this refactor will make a future
replacement of the Url type less noisy.

Connects #11889
Internally the LSP client should hold workspace folders as paths. Using
URLs for this type is inconvenient (since we compare it to paths) and
might cause mismatches because of URLs not being normalized. The URLs
must be paths anyways so we can convert these types lazily when we need
to send them to a server.
CedricMeu pushed a commit to CedricMeu/helix that referenced this pull request Jan 2, 2025
This is a cosmetic change to replace all direct `use`s of the `url::Url`
type in the `helix-lsp-types` crate with `use crate::Url;`. The types
are the same type currently: this refactor will make a future
replacement of the Url type less noisy.

Connects helix-editor#11889
GladkihEgor pushed a commit to GladkihEgor/helix that referenced this pull request Jan 4, 2025
This is a cosmetic change to replace all direct `use`s of the `url::Url`
type in the `helix-lsp-types` crate with `use crate::Url;`. The types
are the same type currently: this refactor will make a future
replacement of the Url type less noisy.

Connects helix-editor#11889
@RoloEdits
Copy link
Contributor

Something I did notice in other work was the conversion of a url to a uri, helix_core::uri::convert_url_to_uri, was very expensive. It ends up calling helix_stdx::path::normalize every time.

image

Not sure if the changes here will help the need for a conversion, mainly the need to normalize, or if this is entirely unavoidable, but thought I'd share at least. If there is a way to check beforehand that it is normalized, like some kind of fast bloom filter-like check, or modeling a just-in-time conversion for when paths are actually used, rather than an ahead-of-time conversion, this could be a big area of improvement.

This seems to happen most in the publish diagnostics hot path:

Notification::PublishDiagnostics(mut params) => {
let uri = match helix_core::Uri::try_from(params.uri) {
Ok(uri) => uri,
Err(err) => {
log::error!("{err}");
return;
}
};

@the-mikedavis
Copy link
Member Author

I'm not 100% sure we can avoid normalizing paths with this change. I imagine that a language server wouldn't send the same file as two different paths (for example ../dir/../a.txt and ../a.txt) especially since they're usually absolute paths, but maybe it's possible. I would say we can probably try not normalizing at first and add it back if needed.

diucicd pushed a commit to diucicd/helix that referenced this pull request Jan 8, 2025
This is a cosmetic change to replace all direct `use`s of the `url::Url`
type in the `helix-lsp-types` crate with `use crate::Url;`. The types
are the same type currently: this refactor will make a future
replacement of the Url type less noisy.

Connects helix-editor#11889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-enhancement Category: Improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
3 participants