@@ -1796,26 +1796,35 @@ impl LanguageClient {
17961796 let filename = self . vim ( ) ?. get_filename ( params) ?;
17971797 let line = self . vim ( ) ?. get_position ( params) ?. line ;
17981798
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+ } ) ?;
18021809 if code_lens. is_empty ( ) {
18031810 warn ! ( "No actions associated with this codeLens" ) ;
18041811 return Ok ( Value :: Null ) ;
18051812 }
18061813
18071814 if code_lens. len ( ) > 1 {
1808- warn ! ( "Mulitple actions associated with this codeLens" ) ;
1815+ warn ! ( "Multiple actions associated with this codeLens" ) ;
18091816 return Ok ( Value :: Null ) ;
18101817 }
18111818
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+ }
18191828 }
18201829 }
18211830
@@ -1838,7 +1847,7 @@ impl LanguageClient {
18381847 let initialize_result: InitializeResult =
18391848 serde_json:: from_value ( initialize_result. clone ( ) ) ?;
18401849 let capabilities = initialize_result. capabilities ;
1841- if capabilities. code_lens_provider . is_some ( ) {
1850+ if let Some ( code_lens_provider ) = capabilities. code_lens_provider {
18421851 info ! ( "Begin {}" , lsp:: request:: CodeLensRequest :: METHOD ) ;
18431852 let client = self . get_client ( & Some ( language_id) ) ?;
18441853 let input = lsp:: CodeLensParams {
@@ -1850,12 +1859,7 @@ impl LanguageClient {
18501859 let results: Value = client. call ( lsp:: request:: CodeLensRequest :: METHOD , & input) ?;
18511860 let code_lens: Option < Vec < CodeLens > > = serde_json:: from_value ( results. clone ( ) ) ?;
18521861
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 ( ) {
18591863 let mut resolved_code_lens = vec ! [ ] ;
18601864 if let Some ( code_lens) = code_lens {
18611865 for item in code_lens {
@@ -2346,18 +2350,10 @@ impl LanguageClient {
23462350 let result = self . textDocument_completion ( params) ?;
23472351 let result: Option < CompletionResponse > = serde_json:: from_value ( result) ?;
23482352 let result = result. unwrap_or_else ( || CompletionResponse :: Array ( vec ! [ ] ) ) ;
2349- let mut matches = match result {
2353+ let matches = match result {
23502354 CompletionResponse :: Array ( arr) => arr,
23512355 CompletionResponse :: List ( list) => list. items ,
23522356 } ;
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- }
23612357
23622358 let complete_position: Option < u64 > = try_get ( "complete_position" , params) ?;
23632359
0 commit comments