@@ -14,7 +14,7 @@ use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc};
1414
1515use anyhow:: Context ;
1616use lsp_server:: Connection ;
17- use paths:: Utf8PathBuf ;
17+ use paths:: { Utf8Component , Utf8PathBuf , Utf8Prefix } ;
1818use rust_analyzer:: {
1919 cli:: flags,
2020 config:: { Config , ConfigChange , ConfigErrors } ,
@@ -207,29 +207,18 @@ fn run_server() -> anyhow::Result<()> {
207207
208208 tracing:: info!( "InitializeParams: {}" , initialize_params) ;
209209 let lsp_types:: InitializeParams {
210+ #[ expect( deprecated, reason = "migration TODO" ) ]
210211 root_uri,
211- mut capabilities,
212- workspace_folders ,
212+ capabilities,
213+ workspace_folders_initialize_params ,
213214 initialization_options,
214215 client_info,
215216 ..
216217 } = from_json :: < lsp_types:: InitializeParams > ( "InitializeParams" , & initialize_params) ?;
217218
218- // lsp-types has a typo in the `/capabilities/workspace/diagnostics` field, its typoed as `diagnostic`
219- if let Some ( val) = initialize_params. pointer ( "/capabilities/workspace/diagnostics" )
220- && let Ok ( diag_caps) = from_json :: < lsp_types:: DiagnosticWorkspaceClientCapabilities > (
221- "DiagnosticWorkspaceClientCapabilities" ,
222- val,
223- )
224- {
225- tracing:: info!( "Patching lsp-types workspace diagnostics capabilities: {diag_caps:#?}" ) ;
226- capabilities. workspace . get_or_insert_default ( ) . diagnostic . get_or_insert ( diag_caps) ;
227- }
228-
229219 let root_path = match root_uri
230- . and_then ( |it| it. to_file_path ( ) . ok ( ) )
220+ . map ( |it| Utf8PathBuf :: from ( it. to_string ( ) . to_owned ( ) ) )
231221 . map ( patch_path_prefix)
232- . and_then ( |it| Utf8PathBuf :: from_path_buf ( it) . ok ( ) )
233222 . and_then ( |it| AbsPathBuf :: try_from ( it) . ok ( ) )
234223 {
235224 Some ( it) => it,
@@ -247,13 +236,19 @@ fn run_server() -> anyhow::Result<()> {
247236 ) ;
248237 }
249238
250- let workspace_roots = workspace_folders
239+ let workspace_roots = workspace_folders_initialize_params
240+ . workspace_folders
241+ . and_then ( |workspaces| match workspaces {
242+ lsp_types:: WorkspaceFolders :: WorkspaceFolderList ( workspace_folders) => {
243+ Some ( workspace_folders)
244+ }
245+ lsp_types:: WorkspaceFolders :: Null => None ,
246+ } )
251247 . map ( |workspaces| {
252248 workspaces
253249 . into_iter ( )
254- . filter_map ( |it| it. uri . to_file_path ( ) . ok ( ) )
250+ . map ( |it| Utf8PathBuf :: from ( it. uri . to_string ( ) ) )
255251 . map ( patch_path_prefix)
256- . filter_map ( |it| Utf8PathBuf :: from_path_buf ( it) . ok ( ) )
257252 . filter_map ( |it| AbsPathBuf :: try_from ( it) . ok ( ) )
258253 . collect :: < Vec < _ > > ( )
259254 } )
@@ -269,12 +264,11 @@ fn run_server() -> anyhow::Result<()> {
269264
270265 if !error_sink. is_empty ( ) {
271266 use lsp_types:: {
272- MessageType , ShowMessageParams ,
273- notification:: { Notification , ShowMessage } ,
267+ MessageType , Notification as _, ShowMessageNotification , ShowMessageParams ,
274268 } ;
275269 let not = lsp_server:: Notification :: new (
276- ShowMessage :: METHOD . to_owned ( ) ,
277- ShowMessageParams { typ : MessageType :: WARNING , message : error_sink. to_string ( ) } ,
270+ ShowMessageNotification :: METHOD . into ( ) ,
271+ ShowMessageParams { kind : MessageType :: Warning , message : error_sink. to_string ( ) } ,
278272 ) ;
279273 connection. sender . send ( lsp_server:: Message :: Notification ( not) ) . unwrap ( ) ;
280274 }
@@ -288,7 +282,6 @@ fn run_server() -> anyhow::Result<()> {
288282 name : String :: from ( "rust-analyzer" ) ,
289283 version : Some ( rust_analyzer:: version ( ) . to_string ( ) ) ,
290284 } ) ,
291- offset_encoding : None ,
292285 } ;
293286
294287 let initialize_result = serde_json:: to_value ( initialize_result) . unwrap ( ) ;
@@ -325,8 +318,7 @@ fn run_server() -> anyhow::Result<()> {
325318 Ok ( ( ) )
326319}
327320
328- fn patch_path_prefix ( path : PathBuf ) -> PathBuf {
329- use std:: path:: { Component , Prefix } ;
321+ fn patch_path_prefix ( path : Utf8PathBuf ) -> Utf8PathBuf {
330322 if cfg ! ( windows) {
331323 // VSCode might report paths with the file drive in lowercase, but this can mess
332324 // with env vars set by tools and build scripts executed by r-a such that it invalidates
@@ -335,17 +327,17 @@ fn patch_path_prefix(path: PathBuf) -> PathBuf {
335327 // (doing it conditionally is a pain because std::path::Prefix always reports uppercase letters on windows)
336328 let mut comps = path. components ( ) ;
337329 match comps. next ( ) {
338- Some ( Component :: Prefix ( prefix) ) => {
330+ Some ( Utf8Component :: Prefix ( prefix) ) => {
339331 let prefix = match prefix. kind ( ) {
340- Prefix :: Disk ( d) => {
332+ Utf8Prefix :: Disk ( d) => {
341333 format ! ( "{}:" , d. to_ascii_uppercase( ) as char )
342334 }
343- Prefix :: VerbatimDisk ( d) => {
335+ Utf8Prefix :: VerbatimDisk ( d) => {
344336 format ! ( r"\\?\{}:" , d. to_ascii_uppercase( ) as char )
345337 }
346338 _ => return path,
347339 } ;
348- let mut path = PathBuf :: new ( ) ;
340+ let mut path = Utf8PathBuf :: new ( ) ;
349341 path. push ( prefix) ;
350342 path. extend ( comps) ;
351343 path
0 commit comments