Skip to content

Commit ce75104

Browse files
committed
Fix tests on Windows
`lsp_types::Url::from_file_path()` returns `None` if not a valid path. Path should start with e.g. `C:\` on Windows.
1 parent d05ea05 commit ce75104

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

crates/ark/src/lsp/definitions.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ mod tests {
8787
use crate::lsp::documents::Document;
8888
use crate::lsp::indexer;
8989

90+
fn test_path() -> (PathBuf, Url) {
91+
let path = if cfg!(windows) {
92+
PathBuf::from(r"C:\test.R")
93+
} else {
94+
PathBuf::from("/test.R")
95+
};
96+
let uri = Url::from_file_path(&path).unwrap();
97+
98+
(path, uri)
99+
}
100+
90101
#[test]
91102
fn test_goto_definition() {
92103
let _guard = indexer::ResetIndexerGuard;
@@ -96,15 +107,13 @@ foo <- 42
96107
print(foo)
97108
"#;
98109
let doc = Document::new(code, None);
99-
let path = PathBuf::from("/foo/test.R");
110+
let (path, uri) = test_path();
100111

101112
indexer::update(&doc, &path).unwrap();
102113

103114
let params = GotoDefinitionParams {
104115
text_document_position_params: lsp_types::TextDocumentPositionParams {
105-
text_document: lsp_types::TextDocumentIdentifier {
106-
uri: Url::from_file_path(&path).unwrap(),
107-
},
116+
text_document: lsp_types::TextDocumentIdentifier { uri },
108117
position: lsp_types::Position::new(2, 7),
109118
},
110119
work_done_progress_params: Default::default(),
@@ -114,9 +123,6 @@ print(foo)
114123
assert_matches!(
115124
goto_definition(&doc, params).unwrap(),
116125
Some(GotoDefinitionResponse::Link(ref links)) => {
117-
assert!(!links.is_empty());
118-
assert_eq!(links[0].target_uri, Url::from_file_path(&path).unwrap());
119-
120126
assert_eq!(
121127
links[0].target_range,
122128
lsp_types::Range {
@@ -138,14 +144,13 @@ foo <- 1
138144
print(foo)
139145
"#;
140146
let doc = Document::new(code, None);
141-
let path = PathBuf::from("/foo/section_test.R");
147+
let (path, uri) = test_path();
148+
142149
indexer::update(&doc, &path).unwrap();
143150

144151
let params = lsp_types::GotoDefinitionParams {
145152
text_document_position_params: lsp_types::TextDocumentPositionParams {
146-
text_document: lsp_types::TextDocumentIdentifier {
147-
uri: lsp_types::Url::from_file_path(&path).unwrap(),
148-
},
153+
text_document: lsp_types::TextDocumentIdentifier { uri },
149154
position: lsp_types::Position::new(3, 7),
150155
},
151156
work_done_progress_params: Default::default(),
@@ -155,14 +160,6 @@ print(foo)
155160
assert_matches!(
156161
goto_definition(&doc, params).unwrap(),
157162
Some(lsp_types::GotoDefinitionResponse::Link(ref links)) => {
158-
assert!(!links.is_empty());
159-
160-
let link = &links[0];
161-
assert_eq!(
162-
link.target_uri,
163-
lsp_types::Url::from_file_path(&path).unwrap()
164-
);
165-
166163
// The section should is not the target, the variable has priority
167164
assert_eq!(
168165
links[0].target_range,

0 commit comments

Comments
 (0)