Compare commits

..

6 Commits

Author SHA1 Message Date
Piotr Osiewicz
bf4e1ffad3 WIP: rainbow brackets 2024-09-12 11:36:36 -04:00
Conrad Irwin
092f29d394 Use a bigger prefix for numeric sorting (#17752)
Release Notes:

- Fixed sorting of files with YYYYmmddHHMMSS prefix
2024-09-12 09:11:19 -04:00
Conrad Irwin
25b6e43b0f bump eslint memory usage (#17724)
Release Notes:

- Increased memory limit for eslint to reduce crashes
2024-09-11 16:22:10 -04:00
Thorsten Ball
3a6a29f117 vim: Fix inline completions showing up in normal mode (#17727)
Booleans are hard.

Release Notes:

- Fixed inline completions showing up in Vim normal mode.
2024-09-11 16:13:17 -04:00
Thorsten Ball
9407d86ce6 project: Use login shell to get environment per project (#17717)
This is a follow-up to #17075 to spawn a login shell when getting the
environment for projects.

The reason why we didn't do it before is that we only used the
environment for certain language servers and not a lot of other things,
like tasks.

But with #17075 we now use the project more often and use it as the
_base_ environment for tasks/terminals.

Before the change, terminals and tasks would inherit the Zed process'
environment, including PATH and so on. After the change, we would set
the environment, overwriting the PATH instead of merging. But the
non-login shell environment is a subset of the login-shell environment.


Release Notes:

- Fixed environment variables used per project in terminals/tasks
overwriting the base environment and not making use of a login-shell
environment.
2024-09-11 13:33:42 -04:00
Thorsten Ball
b5c42edf1e lsp: Fix noisy logs when starting language servers (#17713)
We would log every time we'd lookup a language server for a file and
we'd also log "starting language server" even though we were about to
only download it and not start it.


Release Notes:

- N/A
2024-09-11 12:56:39 -04:00
16 changed files with 86 additions and 42 deletions

1
Cargo.lock generated
View File

@@ -11155,7 +11155,6 @@ dependencies = [
"futures 0.3.30",
"gpui",
"hex",
"log",
"parking_lot",
"schemars",
"serde",

View File

@@ -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.

View File

@@ -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;

View 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![])
}
}

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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
);

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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

View File

@@ -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: {}",

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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

View File

@@ -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
};

View File

@@ -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 {