Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Ignore invalid file URI scheme in parse_file_path et al.#430

Merged
nrc merged 1 commit intorust-lang:masterfrom
Xanewok:non-file-uris
Aug 1, 2017
Merged

Ignore invalid file URI scheme in parse_file_path et al.#430
nrc merged 1 commit intorust-lang:masterfrom
Xanewok:non-file-uris

Conversation

@Xanewok
Copy link
Copy Markdown
Contributor

@Xanewok Xanewok commented Jul 30, 2017

(Somewhat) fixes #421 (and related).

This is a QoL (short-term) fix implemented as per @nrc's #421 (comment):

I think the best short-term solution is to not crash, notice non-file URLs and just ignore them.

This basically introduces UrlFileParseError implementing Error and it's now returned in a Result<T, UrlFileParseError> for parse_file_path and convert_pos_to_span, which uses it.

On an error that's related to invalid URI scheme, it just returns from the handler function.

$log_name and $uri variables in macro are used only for the underlying trace! macro call and I can remove them if it makes things unnecessarily verbose (repeating function name as literal, separating uri binding for clarity etc.).

I know that's not a complete fix, but at least it doesn't crash from what I've seen and properly works if a client edits the local file in Source Control option in VS Code (btw the non-file buffer is read-only in VS Code).

Should I make a separate test case for non-file URIs?

// we don't want to crash the RLS in case a client opens a file under different URI scheme
// like with git:/ or perforce:/ (Probably even http:/? We currently don't support remote schemes).
macro_rules! ignore_non_file_uri {
($expr: expr; $log_name: expr; $uri: expr) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you use commas rather than semi-colons here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I actually can. Previously when I was working on macros I encountered some ambiguities when separating exprs with commas, but it's fine here. Updated

// TODO: Support non-`file` URI schemes in VFS. We're currently ignoring them because
// we don't want to crash the RLS in case a client opens a file under different URI scheme
// like with git:/ or perforce:/ (Probably even http:/? We currently don't support remote schemes).
macro_rules! ignore_non_file_uri {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would probably move the call to parse_file_path into this macro. However, what to do about spans? Maybe call this macro inside the span parsing code and propagate an error later? If that is too much work we could have a macro that parses a uri string to a path or does the error handling like this and another than just does this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe call this macro inside the span parsing code and propagate an error later?

I already propagate the error here. Do you mean something different?

If that is too much work we could have a macro that parses a uri string to a path or does the error handling like this and another than just does this.

Do you mean something like separate parse_file_path_ignore! and convert_pos_to_span_ignore! kind of macros that do what the original functions do (without the unwrap) but still expand to include return; at call site if a resulting error is UrlFileParseError::InvalidScheme?

I think it's okay as a short-term fix, because it's somewhat flexible and doesn't compilate existing parsing/conversion functions, but I'm fine with whatever and can change it, just tell me which change would you prefer 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually convert_pos_to_span requires doc only to retrieve a file Path and uses only that. Maybe we could change the function signature to accept Path instead, revert return type so it returns Span as before (so no error handling would be needed there) and then move the parse_file_path into the ignore_non_file_uri macro as suggested?

@Xanewok Xanewok force-pushed the non-file-uris branch 2 times, most recently from 4bc3d97 to a9276bc Compare July 31, 2017 07:34
@Xanewok
Copy link
Copy Markdown
Contributor Author

Xanewok commented Jul 31, 2017

Pushed new version. Now there are 2 macros, ignore_non_file_uri!, which is the generic version (used in one case other than calling parse_file_path), and parse_file_path!, which is ignore_non_file_uri! with parse_file_path function call moved inside macro.

Moved parsing file name out of convert_pos_to_span as I mentioned in #430 (comment).

@nrc
Copy link
Copy Markdown
Member

nrc commented Aug 1, 2017

Looks good, thanks!

@nrc nrc merged commit 7ecb95e into rust-lang:master Aug 1, 2017
@Xanewok Xanewok deleted the non-file-uris branch August 1, 2017 10:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RLS crashes when passed a non-file URI scheme

2 participants