mirror of https://github.com/helix-editor/helix
Merge 32dfc1647b
into 4281228da3
commit
c950db2057
|
@ -37,6 +37,12 @@ impl From<PathBuf> for Uri {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&Path> for Uri {
|
||||
fn from(path: &Path) -> Self {
|
||||
Self::File(path.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Uri {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
|
|
|
@ -69,7 +69,7 @@ impl Client {
|
|||
self: &Arc<Self>,
|
||||
root_markers: &[String],
|
||||
manual_roots: &[PathBuf],
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
doc_path: Option<&std::path::Path>,
|
||||
may_support_workspace: bool,
|
||||
) -> bool {
|
||||
let (workspace, workspace_is_cwd) = find_workspace();
|
||||
|
|
|
@ -591,7 +591,7 @@ impl Registry {
|
|||
&mut self,
|
||||
name: String,
|
||||
ls_config: &LanguageConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
doc_path: Option<&std::path::Path>,
|
||||
root_dirs: &[PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> Result<Arc<Client>, StartupError> {
|
||||
|
@ -624,7 +624,7 @@ impl Registry {
|
|||
&mut self,
|
||||
name: &str,
|
||||
language_config: &LanguageConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
doc_path: Option<&std::path::Path>,
|
||||
root_dirs: &[PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> Option<Result<Arc<Client>>> {
|
||||
|
@ -679,7 +679,7 @@ impl Registry {
|
|||
pub fn get<'a>(
|
||||
&'a mut self,
|
||||
language_config: &'a LanguageConfiguration,
|
||||
doc_path: Option<&'a std::path::PathBuf>,
|
||||
doc_path: Option<&'a std::path::Path>,
|
||||
root_dirs: &'a [PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> impl Iterator<Item = (LanguageServerName, Result<Arc<Client>>)> + 'a {
|
||||
|
@ -867,7 +867,7 @@ fn start_client(
|
|||
name: String,
|
||||
config: &LanguageConfiguration,
|
||||
ls_config: &LanguageServerConfiguration,
|
||||
doc_path: Option<&std::path::PathBuf>,
|
||||
doc_path: Option<&std::path::Path>,
|
||||
root_dirs: &[PathBuf],
|
||||
enable_snippets: bool,
|
||||
) -> Result<NewClient, StartupError> {
|
||||
|
|
|
@ -2522,7 +2522,7 @@ fn global_search(cx: &mut Context) {
|
|||
|
||||
let documents: Vec<_> = editor
|
||||
.documents()
|
||||
.map(|doc| (doc.path().cloned(), doc.text().to_owned()))
|
||||
.map(|doc| (doc.pathbuf(), doc.text().to_owned()))
|
||||
.collect();
|
||||
|
||||
let matcher = match RegexMatcherBuilder::new()
|
||||
|
@ -3157,7 +3157,7 @@ fn buffer_picker(cx: &mut Context) {
|
|||
|
||||
let new_meta = |doc: &Document| BufferMeta {
|
||||
id: doc.id(),
|
||||
path: doc.path().cloned(),
|
||||
path: doc.pathbuf(),
|
||||
is_modified: doc.is_modified(),
|
||||
is_current: doc.id() == current,
|
||||
focused_at: doc.focused_at,
|
||||
|
@ -3239,7 +3239,7 @@ fn jumplist_picker(cx: &mut Context) {
|
|||
|
||||
JumpMeta {
|
||||
id: doc_id,
|
||||
path: doc.and_then(|d| d.path().cloned()),
|
||||
path: doc.and_then(|doc| doc.pathbuf()),
|
||||
selection,
|
||||
text,
|
||||
is_current: view.doc == doc_id,
|
||||
|
|
|
@ -376,14 +376,13 @@ fn debug_parameter_prompt(
|
|||
|
||||
pub fn dap_toggle_breakpoint(cx: &mut Context) {
|
||||
let (view, doc) = current!(cx.editor);
|
||||
let path = match doc.path() {
|
||||
Some(path) => path.clone(),
|
||||
None => {
|
||||
cx.editor
|
||||
.set_error("Can't set breakpoint: document has no path");
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(path) = doc.pathbuf() else {
|
||||
cx.editor
|
||||
.set_error("Can't set breakpoint: document has no path");
|
||||
return;
|
||||
};
|
||||
|
||||
let text = doc.text().slice(..);
|
||||
let line = doc.selection(view.id).primary().cursor_line(text);
|
||||
dap_toggle_breakpoint_impl(cx, path, line);
|
||||
|
@ -623,9 +622,8 @@ pub fn dap_disable_exceptions(cx: &mut Context) {
|
|||
// TODO: both edit condition and edit log need to be stable: we might get new breakpoints from the debugger which can change offsets
|
||||
pub fn dap_edit_condition(cx: &mut Context) {
|
||||
if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) {
|
||||
let path = match doc!(cx.editor).path() {
|
||||
Some(path) => path.clone(),
|
||||
None => return,
|
||||
let Some(path) = doc!(cx.editor).pathbuf() else {
|
||||
return;
|
||||
};
|
||||
let callback = Box::pin(async move {
|
||||
let call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| {
|
||||
|
@ -665,9 +663,8 @@ pub fn dap_edit_condition(cx: &mut Context) {
|
|||
|
||||
pub fn dap_edit_log(cx: &mut Context) {
|
||||
if let Some((pos, breakpoint)) = get_breakpoint_at_current_line(cx.editor) {
|
||||
let path = match doc!(cx.editor).path() {
|
||||
Some(path) => path.clone(),
|
||||
None => return,
|
||||
let Some(path) = doc!(cx.editor).pathbuf() else {
|
||||
return;
|
||||
};
|
||||
let callback = Box::pin(async move {
|
||||
let call: Callback = Callback::EditorCompositor(Box::new(move |editor, compositor| {
|
||||
|
|
|
@ -315,11 +315,9 @@ pub fn syntax_workspace_symbol_picker(cx: &mut Context) {
|
|||
let pattern = Arc::new(pattern);
|
||||
let injector = injector.clone();
|
||||
let loader = editor.syn_loader.load();
|
||||
let documents: HashSet<_> = editor
|
||||
.documents()
|
||||
.filter_map(Document::path)
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
let documents: HashSet<_> = editor.documents().filter_map(Document::pathbuf).collect();
|
||||
|
||||
async move {
|
||||
let searcher = state.searcher_builder.build();
|
||||
state.walk_builder.build_parallel().run(|| {
|
||||
|
|
|
@ -181,7 +181,7 @@ fn buffer_gather_paths_impl(editor: &mut Editor, args: Args) -> Vec<DocumentId>
|
|||
for arg in args {
|
||||
let doc_id = editor.documents().find_map(|doc| {
|
||||
let arg_path = Some(Path::new(arg.as_ref()));
|
||||
if doc.path().map(|p| p.as_path()) == arg_path || doc.relative_path() == arg_path {
|
||||
if doc.path() == arg_path || doc.relative_path() == arg_path {
|
||||
Some(doc.id())
|
||||
} else {
|
||||
None
|
||||
|
@ -1397,11 +1397,11 @@ fn reload(cx: &mut compositor::Context, _args: Args, event: PromptEvent) -> anyh
|
|||
doc.reload(view, &cx.editor.diff_providers).map(|_| {
|
||||
view.ensure_cursor_in_view(doc, scrolloff);
|
||||
})?;
|
||||
if let Some(path) = doc.path() {
|
||||
if let Some(path) = doc.pathbuf() {
|
||||
cx.editor
|
||||
.language_servers
|
||||
.file_event_handler
|
||||
.file_changed(path.clone());
|
||||
.file_changed(path);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1443,11 +1443,11 @@ fn reload_all(cx: &mut compositor::Context, _args: Args, event: PromptEvent) ->
|
|||
continue;
|
||||
}
|
||||
|
||||
if let Some(path) = doc.path() {
|
||||
if let Some(path) = doc.pathbuf() {
|
||||
cx.editor
|
||||
.language_servers
|
||||
.file_event_handler
|
||||
.file_changed(path.clone());
|
||||
.file_changed(path);
|
||||
}
|
||||
|
||||
for view_id in view_ids {
|
||||
|
@ -2525,9 +2525,8 @@ fn move_buffer(cx: &mut compositor::Context, args: Args, event: PromptEvent) ->
|
|||
|
||||
let doc = doc!(cx.editor);
|
||||
let old_path = doc
|
||||
.path()
|
||||
.context("Scratch buffer cannot be moved. Use :write instead")?
|
||||
.clone();
|
||||
.pathbuf()
|
||||
.context("Scratch buffer cannot be moved. Use :write instead")?;
|
||||
let new_path: PathBuf = args.first().unwrap().into();
|
||||
|
||||
// if new_path is a directory, append the original file name
|
||||
|
|
|
@ -1160,9 +1160,8 @@ impl EditorView {
|
|||
|
||||
let (view, doc) = current!(cxt.editor);
|
||||
|
||||
let path = match doc.path() {
|
||||
Some(path) => path.clone(),
|
||||
None => return EventResult::Ignored(None),
|
||||
let Some(path) = doc.pathbuf() else {
|
||||
return EventResult::Ignored(None);
|
||||
};
|
||||
|
||||
if let Some(char_idx) =
|
||||
|
|
|
@ -466,11 +466,11 @@ where
|
|||
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||
{
|
||||
let title = {
|
||||
let path = context.doc.path();
|
||||
let path = path
|
||||
let path = context
|
||||
.doc
|
||||
.path()
|
||||
.as_ref()
|
||||
.map(|p| p.to_string_lossy())
|
||||
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
|
||||
.map_or_else(|| SCRATCH_BUFFER_NAME.into(), |p| p.to_string_lossy());
|
||||
format!(" {} ", path)
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ async fn test_write_quit_fail() -> anyhow::Result<()> {
|
|||
assert_eq!(1, docs.len());
|
||||
|
||||
let doc = docs.pop().unwrap();
|
||||
assert_eq!(Some(&path::normalize(file.path())), doc.path());
|
||||
assert_eq!(Some(path::normalize(file.path())), doc.pathbuf());
|
||||
assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
|
||||
}),
|
||||
false,
|
||||
|
@ -265,7 +265,7 @@ async fn test_write_scratch_to_new_path() -> anyhow::Result<()> {
|
|||
assert_eq!(1, docs.len());
|
||||
|
||||
let doc = docs.pop().unwrap();
|
||||
assert_eq!(Some(&path::normalize(file.path())), doc.path());
|
||||
assert_eq!(Some(path::normalize(file.path())), doc.pathbuf());
|
||||
}),
|
||||
false,
|
||||
)
|
||||
|
@ -651,7 +651,7 @@ async fn test_symlink_write_fail() -> anyhow::Result<()> {
|
|||
assert_eq!(1, docs.len());
|
||||
|
||||
let doc = docs.pop().unwrap();
|
||||
assert_eq!(Some(&path::normalize(&symlink_path)), doc.path());
|
||||
assert_eq!(Some(path::normalize(&symlink_path)), doc.pathbuf());
|
||||
assert_eq!(&Severity::Error, app.editor.get_status().unwrap().1);
|
||||
}),
|
||||
false,
|
||||
|
|
|
@ -1934,8 +1934,14 @@ impl Document {
|
|||
|
||||
#[inline]
|
||||
/// File path on disk.
|
||||
pub fn path(&self) -> Option<&PathBuf> {
|
||||
self.path.as_ref()
|
||||
pub fn path(&self) -> Option<&Path> {
|
||||
self.path.as_deref()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Owned file path on disk.
|
||||
pub fn pathbuf(&self) -> Option<PathBuf> {
|
||||
self.path.clone()
|
||||
}
|
||||
|
||||
/// File path as a URL.
|
||||
|
@ -1944,7 +1950,7 @@ impl Document {
|
|||
}
|
||||
|
||||
pub fn uri(&self) -> Option<helix_core::Uri> {
|
||||
Some(self.path()?.clone().into())
|
||||
Some(self.path()?.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1540,14 +1540,14 @@ impl Editor {
|
|||
let Some(doc_url) = doc.url() else {
|
||||
return;
|
||||
};
|
||||
let (lang, path) = (doc.language.clone(), doc.path().cloned());
|
||||
let (lang, path) = (doc.language.clone(), doc.path());
|
||||
let config = doc.config.load();
|
||||
let root_dirs = &config.workspace_lsp_roots;
|
||||
|
||||
// store only successfully started language servers
|
||||
let language_servers = lang.as_ref().map_or_else(HashMap::default, |language| {
|
||||
self.language_servers
|
||||
.get(language, path.as_ref(), root_dirs, config.lsp.snippets)
|
||||
.get(language, path, root_dirs, config.lsp.snippets)
|
||||
.filter_map(|(lang, client)| match client {
|
||||
Ok(client) => Some((lang, client)),
|
||||
Err(err) => {
|
||||
|
@ -2061,12 +2061,12 @@ impl Editor {
|
|||
|
||||
pub fn document_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Document> {
|
||||
self.documents()
|
||||
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
|
||||
.find(|doc| doc.path().is_some_and(|p| p == path.as_ref()))
|
||||
}
|
||||
|
||||
pub fn document_by_path_mut<P: AsRef<Path>>(&mut self, path: P) -> Option<&mut Document> {
|
||||
self.documents_mut()
|
||||
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
|
||||
.find(|doc| doc.path().is_some_and(|p| p == path.as_ref()))
|
||||
}
|
||||
|
||||
/// Returns all supported diagnostics for the document
|
||||
|
|
|
@ -284,8 +284,9 @@ fn execution_pause_indicator<'doc>(
|
|||
frame
|
||||
.source
|
||||
.as_ref()
|
||||
.and_then(|source| source.path.as_ref())
|
||||
.and_then(|source| source.path.as_deref())
|
||||
});
|
||||
|
||||
let should_display_for_current_doc =
|
||||
doc.path().is_some() && frame_source_path.unwrap_or(None) == doc.path();
|
||||
|
||||
|
|
Loading…
Reference in New Issue