@@ -87,6 +87,17 @@ mod tests {
87
87
use crate :: lsp:: documents:: Document ;
88
88
use crate :: lsp:: indexer;
89
89
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
+
90
101
#[ test]
91
102
fn test_goto_definition ( ) {
92
103
let _guard = indexer:: ResetIndexerGuard ;
@@ -96,15 +107,13 @@ foo <- 42
96
107
print(foo)
97
108
"# ;
98
109
let doc = Document :: new ( code, None ) ;
99
- let path = PathBuf :: from ( "/foo/test.R" ) ;
110
+ let ( path, uri ) = test_path ( ) ;
100
111
101
112
indexer:: update ( & doc, & path) . unwrap ( ) ;
102
113
103
114
let params = GotoDefinitionParams {
104
115
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 } ,
108
117
position : lsp_types:: Position :: new ( 2 , 7 ) ,
109
118
} ,
110
119
work_done_progress_params : Default :: default ( ) ,
@@ -114,9 +123,6 @@ print(foo)
114
123
assert_matches ! (
115
124
goto_definition( & doc, params) . unwrap( ) ,
116
125
Some ( GotoDefinitionResponse :: Link ( ref links) ) => {
117
- assert!( !links. is_empty( ) ) ;
118
- assert_eq!( links[ 0 ] . target_uri, Url :: from_file_path( & path) . unwrap( ) ) ;
119
-
120
126
assert_eq!(
121
127
links[ 0 ] . target_range,
122
128
lsp_types:: Range {
@@ -138,14 +144,13 @@ foo <- 1
138
144
print(foo)
139
145
"# ;
140
146
let doc = Document :: new ( code, None ) ;
141
- let path = PathBuf :: from ( "/foo/section_test.R" ) ;
147
+ let ( path, uri) = test_path ( ) ;
148
+
142
149
indexer:: update ( & doc, & path) . unwrap ( ) ;
143
150
144
151
let params = lsp_types:: GotoDefinitionParams {
145
152
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 } ,
149
154
position : lsp_types:: Position :: new ( 3 , 7 ) ,
150
155
} ,
151
156
work_done_progress_params : Default :: default ( ) ,
@@ -155,14 +160,6 @@ print(foo)
155
160
assert_matches ! (
156
161
goto_definition( & doc, params) . unwrap( ) ,
157
162
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
-
166
163
// The section should is not the target, the variable has priority
167
164
assert_eq!(
168
165
links[ 0 ] . target_range,
0 commit comments