@@ -974,7 +974,7 @@ pub(crate) fn handle_hover(
974
974
PositionOrRange :: Range ( range) => range,
975
975
} ;
976
976
977
- let file_range = from_proto:: file_range ( & snap, params. text_document , range) ?;
977
+ let file_range = from_proto:: file_range ( & snap, & params. text_document , range) ?;
978
978
let info = match snap. analysis . hover ( & snap. config . hover ( ) , file_range) ? {
979
979
None => return Ok ( None ) ,
980
980
Some ( info) => info,
@@ -1130,7 +1130,7 @@ pub(crate) fn handle_code_action(
1130
1130
1131
1131
let line_index =
1132
1132
snap. file_line_index ( from_proto:: file_id ( & snap, & params. text_document . uri ) ?) ?;
1133
- let frange = from_proto:: file_range ( & snap, params. text_document . clone ( ) , params. range ) ?;
1133
+ let frange = from_proto:: file_range ( & snap, & params. text_document , params. range ) ?;
1134
1134
1135
1135
let mut assists_config = snap. config . assist ( ) ;
1136
1136
assists_config. allowed = params
@@ -1383,7 +1383,7 @@ pub(crate) fn handle_ssr(
1383
1383
let selections = params
1384
1384
. selections
1385
1385
. iter ( )
1386
- . map ( |range| from_proto:: file_range ( & snap, params. position . text_document . clone ( ) , * range) )
1386
+ . map ( |range| from_proto:: file_range ( & snap, & params. position . text_document , * range) )
1387
1387
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
1388
1388
let position = from_proto:: file_position ( & snap, params. position ) ?;
1389
1389
let source_change = snap. analysis . structural_search_replace (
@@ -1403,7 +1403,7 @@ pub(crate) fn handle_inlay_hints(
1403
1403
let document_uri = & params. text_document . uri ;
1404
1404
let FileRange { file_id, range } = from_proto:: file_range (
1405
1405
& snap,
1406
- TextDocumentIdentifier :: new ( document_uri. to_owned ( ) ) ,
1406
+ & TextDocumentIdentifier :: new ( document_uri. to_owned ( ) ) ,
1407
1407
params. range ,
1408
1408
) ?;
1409
1409
let line_index = snap. file_line_index ( file_id) ?;
@@ -1455,7 +1455,7 @@ pub(crate) fn handle_call_hierarchy_incoming(
1455
1455
let item = params. item ;
1456
1456
1457
1457
let doc = TextDocumentIdentifier :: new ( item. uri ) ;
1458
- let frange = from_proto:: file_range ( & snap, doc, item. selection_range ) ?;
1458
+ let frange = from_proto:: file_range ( & snap, & doc, item. selection_range ) ?;
1459
1459
let fpos = FilePosition { file_id : frange. file_id , offset : frange. range . start ( ) } ;
1460
1460
1461
1461
let call_items = match snap. analysis . incoming_calls ( fpos) ? {
@@ -1490,7 +1490,7 @@ pub(crate) fn handle_call_hierarchy_outgoing(
1490
1490
let item = params. item ;
1491
1491
1492
1492
let doc = TextDocumentIdentifier :: new ( item. uri ) ;
1493
- let frange = from_proto:: file_range ( & snap, doc, item. selection_range ) ?;
1493
+ let frange = from_proto:: file_range ( & snap, & doc, item. selection_range ) ?;
1494
1494
let fpos = FilePosition { file_id : frange. file_id , offset : frange. range . start ( ) } ;
1495
1495
1496
1496
let call_items = match snap. analysis . outgoing_calls ( fpos) ? {
@@ -1596,7 +1596,7 @@ pub(crate) fn handle_semantic_tokens_range(
1596
1596
) -> anyhow:: Result < Option < SemanticTokensRangeResult > > {
1597
1597
let _p = profile:: span ( "handle_semantic_tokens_range" ) ;
1598
1598
1599
- let frange = from_proto:: file_range ( & snap, params. text_document , params. range ) ?;
1599
+ let frange = from_proto:: file_range ( & snap, & params. text_document , params. range ) ?;
1600
1600
let text = snap. analysis . file_text ( frange. file_id ) ?;
1601
1601
let line_index = snap. file_line_index ( frange. file_id ) ?;
1602
1602
@@ -1679,7 +1679,7 @@ pub(crate) fn handle_move_item(
1679
1679
) -> anyhow:: Result < Vec < lsp_ext:: SnippetTextEdit > > {
1680
1680
let _p = profile:: span ( "handle_move_item" ) ;
1681
1681
let file_id = from_proto:: file_id ( & snap, & params. text_document . uri ) ?;
1682
- let range = from_proto:: file_range ( & snap, params. text_document , params. range ) ?;
1682
+ let range = from_proto:: file_range ( & snap, & params. text_document , params. range ) ?;
1683
1683
1684
1684
let direction = match params. direction {
1685
1685
lsp_ext:: MoveItemDirection :: Up => ide:: Direction :: Up ,
@@ -1902,23 +1902,7 @@ fn run_rustfmt(
1902
1902
let mut cmd = process:: Command :: new ( toolchain:: rustfmt ( ) ) ;
1903
1903
cmd. envs ( snap. config . extra_env ( ) ) ;
1904
1904
cmd. args ( extra_args) ;
1905
- // try to chdir to the file so we can respect `rustfmt.toml`
1906
- // FIXME: use `rustfmt --config-path` once
1907
- // https://github.com/rust-lang/rustfmt/issues/4660 gets fixed
1908
- match text_document. uri . to_file_path ( ) {
1909
- Ok ( mut path) => {
1910
- // pop off file name
1911
- if path. pop ( ) && path. is_dir ( ) {
1912
- cmd. current_dir ( path) ;
1913
- }
1914
- }
1915
- Err ( _) => {
1916
- tracing:: error!(
1917
- "Unable to get file path for {}, rustfmt.toml might be ignored" ,
1918
- text_document. uri
1919
- ) ;
1920
- }
1921
- }
1905
+
1922
1906
if let Some ( edition) = edition {
1923
1907
cmd. arg ( "--edition" ) ;
1924
1908
cmd. arg ( edition. to_string ( ) ) ;
@@ -1937,7 +1921,7 @@ fn run_rustfmt(
1937
1921
. into ( ) ) ;
1938
1922
}
1939
1923
1940
- let frange = from_proto:: file_range ( snap, text_document, range) ?;
1924
+ let frange = from_proto:: file_range ( snap, & text_document, range) ?;
1941
1925
let start_line = line_index. index . line_col ( frange. range . start ( ) ) . line ;
1942
1926
let end_line = line_index. index . line_col ( frange. range . end ( ) ) . line ;
1943
1927
@@ -1956,12 +1940,31 @@ fn run_rustfmt(
1956
1940
}
1957
1941
RustfmtConfig :: CustomCommand { command, args } => {
1958
1942
let mut cmd = process:: Command :: new ( command) ;
1943
+
1959
1944
cmd. envs ( snap. config . extra_env ( ) ) ;
1960
1945
cmd. args ( args) ;
1961
1946
cmd
1962
1947
}
1963
1948
} ;
1964
1949
1950
+ // try to chdir to the file so we can respect `rustfmt.toml`
1951
+ // FIXME: use `rustfmt --config-path` once
1952
+ // https://github.com/rust-lang/rustfmt/issues/4660 gets fixed
1953
+ match text_document. uri . to_file_path ( ) {
1954
+ Ok ( mut path) => {
1955
+ // pop off file name
1956
+ if path. pop ( ) && path. is_dir ( ) {
1957
+ command. current_dir ( path) ;
1958
+ }
1959
+ }
1960
+ Err ( _) => {
1961
+ tracing:: error!(
1962
+ text_document = ?text_document. uri,
1963
+ "Unable to get path, rustfmt.toml might be ignored"
1964
+ ) ;
1965
+ }
1966
+ }
1967
+
1965
1968
let mut rustfmt = command
1966
1969
. stdin ( Stdio :: piped ( ) )
1967
1970
. stdout ( Stdio :: piped ( ) )
0 commit comments