@@ -27,7 +27,7 @@ use lsp_types::{
2727use project_model:: TargetKind ;
2828use serde_json:: json;
2929use stdx:: { format_to, never} ;
30- use syntax:: { algo, ast, AstNode , TextRange , TextSize } ;
30+ use syntax:: { algo, ast, AstNode , TextRange , TextSize , T } ;
3131
3232use crate :: {
3333 cargo_target_spec:: CargoTargetSpec ,
@@ -727,16 +727,13 @@ pub(crate) fn handle_completion(
727727 let completion_triggered_after_single_colon = {
728728 let mut res = false ;
729729 if let Some ( ctx) = params. context {
730- if ctx. trigger_character . unwrap_or_default ( ) == ":" {
730+ if ctx. trigger_character . as_deref ( ) == Some ( ":" ) {
731731 let source_file = snap. analysis . parse ( position. file_id ) ?;
732- let syntax = source_file. syntax ( ) ;
733- let text = syntax. text ( ) ;
734- if let Some ( next_char) = text. char_at ( position. offset ) {
735- let diff = TextSize :: of ( next_char) + TextSize :: of ( ':' ) ;
736- let prev_char = position. offset - diff;
737- if text. char_at ( prev_char) != Some ( ':' ) {
738- res = true ;
739- }
732+ let left_token =
733+ source_file. syntax ( ) . token_at_offset ( position. offset ) . left_biased ( ) ;
734+ match left_token {
735+ Some ( left_token) => res = left_token. kind ( ) == T ! [ : ] ,
736+ None => res = true ,
740737 }
741738 }
742739 }
0 commit comments