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

Switch to storing URIs in entries instead of file paths #2341

Closed
wants to merge 1 commit into from

Conversation

vinistock
Copy link
Member

Motivation

First step towards #2340 and #1908

Currently, we save the file paths for entries in the index. This decision is incompatible with how language servers work, because you can have files that exist in different URI schemes (such as the one for unsaved files like untitled:Untitled-1).

In general, we should always strive to use URIs everywhere and only get the file paths when we want to return something or when we're reading from disk.

This PR changes our entries to store the URIs where they were declared, rather than tying ourselves with file paths. This change is necessary in order to fix #1908, because if we index files before they are saved, there's no file path associated to the declarations being made in the unsaved file.

Implementation

The change is essentially switching from file_path to URI pretty much everywhere.

As an added benefit, we now no longer need to build the URI when serving features, because that's already available directly in the entries - which is another indication that standardizing on URIs is likely the best choice.

Automated Tests

Adapted existing tests.

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Jul 22, 2024
@vinistock vinistock self-assigned this Jul 22, 2024
@vinistock vinistock requested a review from a team as a code owner July 22, 2024 20:06
@vinistock vinistock requested review from andyw8 and st0012 July 22, 2024 20:06
@andyw8
Copy link
Contributor

andyw8 commented Jul 23, 2024

🤔 Will this have any impact on addons?

@@ -2,6 +2,8 @@
# frozen_string_literal: true

module RubyIndexer
# Represents a file system path that can be indexed. This class should only be used for files in the file system and
# not for other URIs that may be indexed, such as unsaved file URIs using the `untitled` scheme
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not enforce this by using URI::File instead of URI::Generic?

# }
@files_to_entries = T.let({}, T::Hash[String, T::Array[Entry]])
@uris_to_entries = T.let({}, T::Hash[String, T::Array[Entry]])
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change this to use the URI as the key?

Copy link
Contributor

This pull request is being marked as stale because there was no activity in the last 2 months

@github-actions github-actions bot added the Stale label Sep 22, 2024
@vinistock
Copy link
Member Author

Closing this for now. We need to re-think the approach.

@vinistock vinistock closed this Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make completions available for newly-added symbols in unsaved files
3 participants