Compare commits
6 Commits
path-env
...
rainbow_br
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf4e1ffad3 | ||
|
|
092f29d394 | ||
|
|
25b6e43b0f | ||
|
|
3a6a29f117 | ||
|
|
9407d86ce6 | ||
|
|
b5c42edf1e |
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -11155,7 +11155,6 @@ dependencies = [
|
||||
"futures 0.3.30",
|
||||
"gpui",
|
||||
"hex",
|
||||
"log",
|
||||
"parking_lot",
|
||||
"schemars",
|
||||
"serde",
|
||||
|
||||
@@ -439,6 +439,7 @@
|
||||
// The list of language servers to use (or disable) for all languages.
|
||||
//
|
||||
// This is typically customized on a per-language basis.
|
||||
"rainbow_brackets": true,
|
||||
"language_servers": ["..."],
|
||||
// When to automatically save edited buffers. This setting can
|
||||
// take four values.
|
||||
|
||||
@@ -4975,9 +4975,10 @@ impl Editor {
|
||||
let cursor = self.selections.newest_anchor().head();
|
||||
let (buffer, cursor_buffer_position) =
|
||||
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
|
||||
|
||||
if !user_requested
|
||||
&& self.enable_inline_completions
|
||||
&& !self.should_show_inline_completions(&buffer, cursor_buffer_position, cx)
|
||||
&& (!self.enable_inline_completions
|
||||
|| !self.should_show_inline_completions(&buffer, cursor_buffer_position, cx))
|
||||
{
|
||||
self.discard_inline_completion(false, cx);
|
||||
return None;
|
||||
|
||||
25
crates/language/src/bracket_map.rs
Normal file
25
crates/language/src/bracket_map.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use gpui::{HighlightStyle, Hsla};
|
||||
use std::sync::Arc;
|
||||
use theme::{AccentColors, SyntaxTheme};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BracketMap(Vec<Hsla>);
|
||||
|
||||
impl BracketMap {
|
||||
pub(crate) fn new(colors: AccentColors) -> Self {
|
||||
// For each capture name in the highlight query, find the longest
|
||||
// key in the theme's syntax styles that matches all of the
|
||||
// dot-separated components of the capture name.
|
||||
BracketMap(colors.0)
|
||||
}
|
||||
|
||||
pub fn get(&self, depth: u32) -> Hsla {
|
||||
self.0.get(depth % self.0.len()).copied().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BracketMap {
|
||||
fn default() -> Self {
|
||||
Self(vec![])
|
||||
}
|
||||
}
|
||||
@@ -2574,16 +2574,20 @@ impl BufferSnapshot {
|
||||
None
|
||||
}
|
||||
|
||||
fn get_highlights(&self, range: Range<usize>) -> (SyntaxMapCaptures, Vec<HighlightMap>) {
|
||||
fn get_highlights(&self, range: Range<usize>) -> (SyntaxMapCaptures, Vec<HighlightMap>, usize) {
|
||||
//let settings = self.settings_at(range.start, cx).rainbow_brackets;
|
||||
let captures = self.syntax.captures(range, &self.text, |grammar| {
|
||||
grammar.highlights_query.as_ref()
|
||||
grammar
|
||||
.highlights_with_brackets_query
|
||||
.as_ref()
|
||||
.map(|(query, _)| query)
|
||||
});
|
||||
let highlight_maps = captures
|
||||
.grammars()
|
||||
.iter()
|
||||
.map(|grammar| grammar.highlight_map())
|
||||
.collect();
|
||||
(captures, highlight_maps)
|
||||
(captures, highlight_maps, bracket_patterns_count)
|
||||
}
|
||||
/// Iterates over chunks of text in the given range of the buffer. Text is chunked
|
||||
/// in an arbitrary way due to being stored in a [`Rope`](text::Rope). The text is also
|
||||
|
||||
@@ -62,7 +62,7 @@ use task::RunnableTag;
|
||||
pub use task_context::{ContextProvider, RunnableRange};
|
||||
use theme::SyntaxTheme;
|
||||
use tree_sitter::{self, wasmtime, Query, QueryCursor, WasmStore};
|
||||
use util::serde::default_true;
|
||||
use util::{maybe, serde::default_true};
|
||||
|
||||
pub use buffer::Operation;
|
||||
pub use buffer::*;
|
||||
@@ -848,6 +848,7 @@ impl GrammarId {
|
||||
}
|
||||
}
|
||||
|
||||
struct HighlighBracketsQuery(Query, usize);
|
||||
pub struct Grammar {
|
||||
id: GrammarId,
|
||||
pub ts_language: tree_sitter::Language,
|
||||
@@ -862,6 +863,7 @@ pub struct Grammar {
|
||||
pub(crate) injection_config: Option<InjectionConfig>,
|
||||
pub(crate) override_config: Option<OverrideConfig>,
|
||||
pub(crate) highlight_map: Mutex<HighlightMap>,
|
||||
pub(crate) highlights_with_brackets_query: Option<(Query, usize)>,
|
||||
}
|
||||
|
||||
struct IndentConfig {
|
||||
@@ -962,6 +964,7 @@ impl Language {
|
||||
error_query: Query::new(&ts_language, "(ERROR) @error").unwrap(),
|
||||
ts_language,
|
||||
highlight_map: Default::default(),
|
||||
highlights_with_brackets_query: None,
|
||||
})
|
||||
}),
|
||||
context_provider: None,
|
||||
@@ -974,12 +977,12 @@ impl Language {
|
||||
}
|
||||
|
||||
pub fn with_queries(mut self, queries: LanguageQueries) -> Result<Self> {
|
||||
if let Some(query) = queries.highlights {
|
||||
if let Some(query) = queries.highlights.as_ref() {
|
||||
self = self
|
||||
.with_highlights_query(query.as_ref())
|
||||
.context("Error loading highlights query")?;
|
||||
}
|
||||
if let Some(query) = queries.brackets {
|
||||
if let Some(query) = queries.brackets.as_ref() {
|
||||
self = self
|
||||
.with_brackets_query(query.as_ref())
|
||||
.context("Error loading brackets query")?;
|
||||
@@ -1019,6 +1022,34 @@ impl Language {
|
||||
.with_runnable_query(query.as_ref())
|
||||
.context("Error loading tests query")?;
|
||||
}
|
||||
if let Some((brackets, highlights)) = queries.brackets.zip(queries.highlights) {
|
||||
self = self
|
||||
.with_highlights_and_brackets_query(&brackets, &highlights)
|
||||
.context("Error loading rainbow brackets query")?;
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_highlights_and_brackets_query(
|
||||
mut self,
|
||||
brackets: &str,
|
||||
highlights: &str,
|
||||
) -> Result<Self> {
|
||||
let grammar = self
|
||||
.grammar_mut()
|
||||
.ok_or_else(|| anyhow!("cannot mutate grammar"))?;
|
||||
let merged_query = format!("{brackets}\n{highlights}");
|
||||
let brackets_count = grammar
|
||||
.brackets_config
|
||||
.as_ref()
|
||||
.expect("Expected bracket query to be initialized")
|
||||
.query
|
||||
.pattern_count();
|
||||
|
||||
grammar.highlights_with_brackets_query = Some((
|
||||
Query::new(&grammar.ts_language, &merged_query)?,
|
||||
brackets_count,
|
||||
));
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -833,7 +833,7 @@ impl LanguageRegistry {
|
||||
) -> Option<PendingLanguageServer> {
|
||||
let server_id = self.state.write().next_language_server_id();
|
||||
log::info!(
|
||||
"starting language server {:?}, path: {root_path:?}, id: {server_id}",
|
||||
"attempting to start language server {:?}, path: {root_path:?}, id: {server_id}",
|
||||
adapter.name.0
|
||||
);
|
||||
|
||||
|
||||
@@ -121,6 +121,9 @@ pub struct LanguageSettings {
|
||||
pub linked_edits: bool,
|
||||
/// Task configuration for this language.
|
||||
pub tasks: LanguageTaskConfig,
|
||||
|
||||
/// Rainbow brackets config
|
||||
pub rainbow_brackets: bool,
|
||||
}
|
||||
|
||||
impl LanguageSettings {
|
||||
@@ -345,6 +348,10 @@ pub struct LanguageSettingsContent {
|
||||
///
|
||||
/// Default: {}
|
||||
pub tasks: Option<LanguageTaskConfig>,
|
||||
/// Task configuration for this language.
|
||||
///
|
||||
/// Default: {}
|
||||
pub rainbow_brackets: Option<bool>,
|
||||
}
|
||||
|
||||
/// The contents of the inline completion settings.
|
||||
|
||||
@@ -58,7 +58,11 @@ fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||
}
|
||||
|
||||
fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||
vec![server_path.into(), "--stdio".into()]
|
||||
vec![
|
||||
"--max-old-space-size=8192".into(),
|
||||
server_path.into(),
|
||||
"--stdio".into(),
|
||||
]
|
||||
}
|
||||
|
||||
pub struct TypeScriptLspAdapter {
|
||||
|
||||
@@ -272,7 +272,7 @@ impl LanguageServer {
|
||||
};
|
||||
|
||||
log::info!(
|
||||
"starting language server. binary path: {:?}, working directory: {:?}, args: {:?}",
|
||||
"starting language server process. binary path: {:?}, working directory: {:?}, args: {:?}",
|
||||
binary.path,
|
||||
working_dir,
|
||||
&binary.arguments
|
||||
|
||||
@@ -218,10 +218,8 @@ async fn load_shell_environment(
|
||||
additional_command.unwrap_or("")
|
||||
);
|
||||
|
||||
log::error!("loading shell env for project with this command: {command:?}. direnv_environment: {direnv_environment:?}");
|
||||
|
||||
let output = smol::process::Command::new(&shell)
|
||||
.args(["-i", "-c", &command])
|
||||
.args(["-l", "-i", "-c", &command])
|
||||
.envs(direnv_environment)
|
||||
.output()
|
||||
.await
|
||||
@@ -234,8 +232,6 @@ async fn load_shell_environment(
|
||||
);
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
log::error!("loaded login shell for project. stdout: {stdout:?}");
|
||||
|
||||
let env_output_start = stdout.find(marker).ok_or_else(|| {
|
||||
anyhow!(
|
||||
"failed to parse output of `env` command in login shell: {}",
|
||||
|
||||
@@ -26,7 +26,6 @@ use gpui::{
|
||||
Task, WeakModel,
|
||||
};
|
||||
use http_client::{AsyncBody, Error, HttpClient, Request, Response, Uri};
|
||||
use itertools::Itertools;
|
||||
use language::{
|
||||
language_settings::{
|
||||
all_language_settings, language_settings, AllLanguageSettings, LanguageSettings,
|
||||
@@ -4489,14 +4488,6 @@ impl LspStore {
|
||||
);
|
||||
}
|
||||
|
||||
log::info!(
|
||||
"starting language servers for {language}: {adapters}",
|
||||
adapters = enabled_lsp_adapters
|
||||
.iter()
|
||||
.map(|adapter| adapter.name.0.as_ref())
|
||||
.join(", ")
|
||||
);
|
||||
|
||||
for adapter in &enabled_lsp_adapters {
|
||||
self.start_language_server(worktree, adapter.clone(), language.clone(), cx);
|
||||
}
|
||||
|
||||
@@ -118,11 +118,6 @@ impl Project {
|
||||
.read(cx)
|
||||
.get_cli_environment()
|
||||
.unwrap_or_default();
|
||||
|
||||
log::error!("get_cli_environment().PATH: {:?}", env.get("PATH"));
|
||||
log::error!("settings.env: {:?}", settings.env.get("PATH"));
|
||||
log::error!("os.env: {:?}", env::var("PATH"));
|
||||
|
||||
// Then extend it with the explicit env variables from the settings, so they take
|
||||
// precedence.
|
||||
env.extend(settings.env.clone());
|
||||
@@ -174,7 +169,6 @@ impl Project {
|
||||
completion_rx,
|
||||
});
|
||||
|
||||
log::error!("spawn_task.env.PATH: {:?}", spawn_task.env.get("PATH"));
|
||||
env.extend(spawn_task.env);
|
||||
|
||||
if let Some(venv_path) = &python_venv_directory {
|
||||
|
||||
@@ -14,7 +14,6 @@ collections.workspace = true
|
||||
futures.workspace = true
|
||||
gpui.workspace = true
|
||||
hex.workspace = true
|
||||
log.workspace = true
|
||||
parking_lot.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
|
||||
@@ -185,8 +185,6 @@ impl TaskTemplate {
|
||||
let env = {
|
||||
// Start with the project environment as the base.
|
||||
let mut env = cx.project_env.clone();
|
||||
log::error!("cx.project_env.PATH {:?}", env.get("PATH"));
|
||||
log::error!("self.env.PATH {:?}", self.env.get("PATH"));
|
||||
|
||||
// Extend that environment with what's defined in the TaskTemplate
|
||||
env.extend(self.env.clone());
|
||||
@@ -199,14 +197,8 @@ impl TaskTemplate {
|
||||
&mut substituted_variables,
|
||||
)?;
|
||||
|
||||
log::error!(
|
||||
"env.PATH after replacing template variables in map: {:?}",
|
||||
env.get("PATH")
|
||||
);
|
||||
|
||||
// Last step: set the task variables as environment variables too
|
||||
env.extend(task_variables.into_iter().map(|(k, v)| (k, v.to_owned())));
|
||||
|
||||
env
|
||||
};
|
||||
|
||||
|
||||
@@ -644,7 +644,7 @@ impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
|
||||
/// This is useful for turning regular alphanumerically sorted sequences as `1-abc, 10, 11-def, .., 2, 21-abc`
|
||||
/// into `1-abc, 2, 10, 11-def, .., 21-abc`
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct NumericPrefixWithSuffix<'a>(Option<u32>, &'a str);
|
||||
pub struct NumericPrefixWithSuffix<'a>(Option<u64>, &'a str);
|
||||
|
||||
impl<'a> NumericPrefixWithSuffix<'a> {
|
||||
pub fn from_numeric_prefixed_str(str: &'a str) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user