@@ -1796,26 +1796,35 @@ impl LanguageClient {
1796
1796
let filename = self . vim ( ) ?. get_filename ( params) ?;
1797
1797
let line = self . vim ( ) ?. get_position ( params) ?. line ;
1798
1798
1799
- let mut code_lens: Vec < CodeLens > =
1800
- self . get ( |state| state. code_lens . get ( filename. as_str ( ) ) . cloned ( ) . unwrap ( ) ) ?;
1801
- code_lens. retain ( |cl| cl. range . start . line == line) ;
1799
+ let code_lens: Vec < CodeLens > = self . get ( |state| {
1800
+ state
1801
+ . code_lens
1802
+ . get ( & filename)
1803
+ . cloned ( )
1804
+ . unwrap_or_else ( Vec :: new)
1805
+ . into_iter ( )
1806
+ . filter ( |action| action. range . start . line == line)
1807
+ . collect ( )
1808
+ } ) ?;
1802
1809
if code_lens. is_empty ( ) {
1803
1810
warn ! ( "No actions associated with this codeLens" ) ;
1804
1811
return Ok ( Value :: Null ) ;
1805
1812
}
1806
1813
1807
1814
if code_lens. len ( ) > 1 {
1808
- warn ! ( "Mulitple actions associated with this codeLens" ) ;
1815
+ warn ! ( "Multiple actions associated with this codeLens" ) ;
1809
1816
return Ok ( Value :: Null ) ;
1810
1817
}
1811
1818
1812
- if let Some ( command) = code_lens. pop ( ) . unwrap ( ) . command {
1813
- if !self . try_handle_command_by_client ( & command) ? {
1814
- let params = json ! ( {
1815
- "command" : command. command,
1816
- "arguments" : command. arguments,
1817
- } ) ;
1818
- self . workspace_executeCommand ( & params) ?;
1819
+ if let Some ( code_lens_action) = code_lens. get ( 0 ) {
1820
+ if let Some ( command) = & code_lens_action. command {
1821
+ if !self . try_handle_command_by_client ( & command) ? {
1822
+ let params = json ! ( {
1823
+ "command" : command. command,
1824
+ "arguments" : command. arguments,
1825
+ } ) ;
1826
+ self . workspace_executeCommand ( & params) ?;
1827
+ }
1819
1828
}
1820
1829
}
1821
1830
@@ -1838,7 +1847,7 @@ impl LanguageClient {
1838
1847
let initialize_result: InitializeResult =
1839
1848
serde_json:: from_value ( initialize_result. clone ( ) ) ?;
1840
1849
let capabilities = initialize_result. capabilities ;
1841
- if capabilities. code_lens_provider . is_some ( ) {
1850
+ if let Some ( code_lens_provider ) = capabilities. code_lens_provider {
1842
1851
info ! ( "Begin {}" , lsp:: request:: CodeLensRequest :: METHOD ) ;
1843
1852
let client = self . get_client ( & Some ( language_id) ) ?;
1844
1853
let input = lsp:: CodeLensParams {
@@ -1850,12 +1859,7 @@ impl LanguageClient {
1850
1859
let results: Value = client. call ( lsp:: request:: CodeLensRequest :: METHOD , & input) ?;
1851
1860
let code_lens: Option < Vec < CodeLens > > = serde_json:: from_value ( results. clone ( ) ) ?;
1852
1861
1853
- if capabilities
1854
- . code_lens_provider
1855
- . unwrap ( )
1856
- . resolve_provider
1857
- . is_some ( )
1858
- {
1862
+ if code_lens_provider. resolve_provider . is_some ( ) {
1859
1863
let mut resolved_code_lens = vec ! [ ] ;
1860
1864
if let Some ( code_lens) = code_lens {
1861
1865
for item in code_lens {
@@ -2346,18 +2350,10 @@ impl LanguageClient {
2346
2350
let result = self . textDocument_completion ( params) ?;
2347
2351
let result: Option < CompletionResponse > = serde_json:: from_value ( result) ?;
2348
2352
let result = result. unwrap_or_else ( || CompletionResponse :: Array ( vec ! [ ] ) ) ;
2349
- let mut matches = match result {
2353
+ let matches = match result {
2350
2354
CompletionResponse :: Array ( arr) => arr,
2351
2355
CompletionResponse :: List ( list) => list. items ,
2352
2356
} ;
2353
- if !matches. iter ( ) . any ( |m| m. sort_text . is_none ( ) ) {
2354
- matches. sort_by ( |m1, m2| {
2355
- m1. sort_text
2356
- . as_ref ( )
2357
- . unwrap ( )
2358
- . cmp ( m2. sort_text . as_ref ( ) . unwrap ( ) )
2359
- } ) ;
2360
- }
2361
2357
2362
2358
let complete_position: Option < u64 > = try_get ( "complete_position" , params) ?;
2363
2359
0 commit comments