WIP: Add a setting to visually redact enviroment variables (#7124)
Release Notes: - Added bash syntax highlighting to `.env` files. - Added a `private_files` setting for configuring which files should be considered to contain environment variables or other sensitive information. - Added a `redact_private_values` setting to add or remove censor bars over variable values in files matching the `private_files` patterns. -(internal) added a new `redactions.scm` query to our language support, allowing different config file formats to indicate where environment variable values can be identified in the syntax tree, added this query to `bash`, `json`, `toml`, and `yaml` files. --------- Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
5333eff0e4
commit
f98d636203
23 changed files with 330 additions and 32 deletions
|
@ -383,6 +383,9 @@ pub trait File: Send + Sync {
|
|||
|
||||
/// Converts this file into a protobuf message.
|
||||
fn to_proto(&self) -> rpc::proto::File;
|
||||
|
||||
/// Return whether Zed considers this to be a dotenv file.
|
||||
fn is_private(&self) -> bool;
|
||||
}
|
||||
|
||||
/// The file associated with a buffer, in the case where the file is on the local disk.
|
||||
|
@ -2877,6 +2880,43 @@ impl BufferSnapshot {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns anchor ranges for any matches of the redaction query.
|
||||
/// The buffer can be associated with multiple languages, and the redaction query associated with each
|
||||
/// will be run on the relevant section of the buffer.
|
||||
pub fn redacted_ranges<'a, T: ToOffset>(
|
||||
&'a self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = Range<usize>> + 'a {
|
||||
let offset_range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut syntax_matches = self.syntax.matches(offset_range, self, |grammar| {
|
||||
grammar
|
||||
.redactions_config
|
||||
.as_ref()
|
||||
.map(|config| &config.query)
|
||||
});
|
||||
|
||||
let configs = syntax_matches
|
||||
.grammars()
|
||||
.iter()
|
||||
.map(|grammar| grammar.redactions_config.as_ref())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
iter::from_fn(move || {
|
||||
let redacted_range = syntax_matches
|
||||
.peek()
|
||||
.and_then(|mat| {
|
||||
configs[mat.grammar_index].and_then(|config| {
|
||||
mat.captures
|
||||
.iter()
|
||||
.find(|capture| capture.index == config.redaction_capture_ix)
|
||||
})
|
||||
})
|
||||
.map(|mat| mat.node.byte_range());
|
||||
syntax_matches.advance();
|
||||
redacted_range
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns selections for remote peers intersecting the given range.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn remote_selections_in_range(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue