diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 5ac33a9c..d2412025 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -63,6 +63,7 @@ jobs: - run: rustup component add clippy - name: Install dependencies on Ubuntu run: sudo apt-get update && sudo apt-get install cmake pkg-config libgtk-3-dev + - uses: Swatinem/rust-cache@v1 - uses: actions-rs/cargo@v1 with: command: clippy diff --git a/lapce-data/src/palette.rs b/lapce-data/src/palette.rs index 6be4823b..b3475f2e 100644 --- a/lapce-data/src/palette.rs +++ b/lapce-data/src/palette.rs @@ -74,6 +74,28 @@ pub fn has_preview(&self) -> bool { | PaletteType::Reference ) } + + /// Get the palette type that it should be considered as based on the current + /// [`PaletteType`] and the current input. + fn get_palette_type(current_type: &PaletteType, input: &str) -> PaletteType { + match current_type { + PaletteType::Reference | PaletteType::SshHost | PaletteType::Theme => { + return current_type.clone(); + } + _ => (), + } + if input.is_empty() { + return PaletteType::File; + } + match input { + _ if input.starts_with('/') => PaletteType::Line, + _ if input.starts_with('@') => PaletteType::DocumentSymbol, + _ if input.starts_with('#') => PaletteType::WorkspaceSymbol, + _ if input.starts_with('>') => PaletteType::Workspace, + _ if input.starts_with(':') => PaletteType::Command, + _ => PaletteType::File, + } + } } #[derive(Clone, Debug, PartialEq)] @@ -678,13 +700,15 @@ pub fn update_input(&mut self, ctx: &mut EventCtx, input: String) { let palette = Arc::make_mut(&mut self.palette); // WorkspaceSymbol requires sending the query to the lsp, so we refresh it when the input changes - if input != palette.input - && matches!(palette.palette_type, PaletteType::WorkspaceSymbol) - { + // If the input changed and the palette type is still/now workspace-symbol then we rerun it + let palette_type = + PaletteType::get_palette_type(&palette.palette_type, &input); + if input != palette.input && palette_type == PaletteType::WorkspaceSymbol { self.run(ctx, Some(PaletteType::WorkspaceSymbol), Some(input)); return; } + // Update the current input palette.input = input; self.update_palette(ctx) @@ -693,7 +717,11 @@ pub fn update_input(&mut self, ctx: &mut EventCtx, input: String) { pub fn update_palette(&mut self, ctx: &mut EventCtx) { let palette = Arc::make_mut(&mut self.palette); palette.index = 0; - let palette_type = self.get_palette_type(); + + let palette_type = PaletteType::get_palette_type( + &self.palette.palette_type, + &self.palette.input, + ); if self.palette.palette_type != palette_type { self.run(ctx, Some(palette_type), None); return; @@ -710,26 +738,6 @@ pub fn update_palette(&mut self, ctx: &mut EventCtx) { } } - fn get_palette_type(&self) -> PaletteType { - match self.palette.palette_type { - PaletteType::Reference | PaletteType::SshHost | PaletteType::Theme => { - return self.palette.palette_type.clone(); - } - _ => (), - } - if self.palette.input.is_empty() { - return PaletteType::File; - } - match self.palette.input { - _ if self.palette.input.starts_with('/') => PaletteType::Line, - _ if self.palette.input.starts_with('@') => PaletteType::DocumentSymbol, - _ if self.palette.input.starts_with('#') => PaletteType::WorkspaceSymbol, - _ if self.palette.input.starts_with('>') => PaletteType::Workspace, - _ if self.palette.input.starts_with(':') => PaletteType::Command, - _ => PaletteType::File, - } - } - fn get_files(&self, ctx: &mut EventCtx) { let run_id = self.palette.run_id.clone(); let widget_id = self.palette.widget_id;