Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Mar 31, 2024
1 parent 68401a8 commit 361ad23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
16 changes: 8 additions & 8 deletions autoload/clap/plugin/diagnostics.vim
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,24 @@ endfunction
function! s:add_eol(bufnr, diagnostics) abort
let extmark_ids = s:render_eol(a:bufnr, a:diagnostics)

let clap_diagnostics = getbufvar(a:bufnr, 'clap_diagnostics', {})
if has_key(clap_diagnostics, 'extmark_ids')
call extend(clap_diagnostics.extmark_ids, extmark_ids)
call setbufvar(a:bufnr, 'clap_diagnostics', clap_diagnostics)
let __clap_diagnostics = getbufvar(a:bufnr, '__clap_diagnostics', {})
if has_key(__clap_diagnostics, 'extmark_ids')
call extend(__clap_diagnostics.extmark_ids, extmark_ids)
call setbufvar(a:bufnr, '__clap_diagnostics', __clap_diagnostics)
endif
endfunction

function! s:refresh_eol(bufnr, diagnostics) abort
let extmark_ids = s:render_eol(a:bufnr, a:diagnostics)
call setbufvar(a:bufnr, 'clap_diagnostics', { 'extmark_ids': extmark_ids })
call setbufvar(a:bufnr, '__clap_diagnostics', { 'extmark_ids': extmark_ids })
endfunction

function! s:delete_eol(bufnr) abort
let clap_diagnostics = getbufvar(a:bufnr, 'clap_diagnostics', {})
for id in get(clap_diagnostics, 'extmark_ids', [])
let __clap_diagnostics = getbufvar(a:bufnr, '__clap_diagnostics', {})
for id in get(__clap_diagnostics, 'extmark_ids', [])
call nvim_buf_del_extmark(a:bufnr, s:diagnostic_eol_ns_id, id)
endfor
call setbufvar(a:bufnr, 'clap_diagnostics', {})
call setbufvar(a:bufnr, '__clap_diagnostics', {})
endfunction

function! clap#plugin#diagnostics#delete_highlights(bufnr) abort
Expand Down
1 change: 1 addition & 0 deletions crates/code_tools/src/linting/linters/typos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct PathContext {
#[non_exhaustive]
enum Context {
File(FileContext),
#[allow(unused)]
Path(PathContext),
}

Expand Down
45 changes: 28 additions & 17 deletions crates/maple_lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde_json::Value;
use std::collections::HashMap;
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::process::{Child, ChildStdin, ChildStdout, Command, Stdio};
use std::process::{Child, ChildStderr, ChildStdin, ChildStdout, Command, Stdio};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use tokio::sync::mpsc::error::SendError;
Expand Down Expand Up @@ -473,6 +473,29 @@ fn spawn_task_stdin(stdin: ChildStdin) -> UnboundedSender<RpcMessage> {
payload_sender
}

fn spawn_task_stderr(stderr: ChildStderr, server_name: String) {
tokio::task::spawn_blocking(move || {
let mut reader = Box::new(BufReader::new(stderr));

loop {
let mut line = String::new();
match reader.read_line(&mut line) {
Ok(n) => {
if n == 0 {
// Stream closed.
return;
}
tracing::debug!("[{server_name}] error: {}", line.trim_end());
}
Err(err) => {
tracing::error!("Error occurred at reading child stderr: {err:?}");
return;
}
}
}
});
}

#[derive(Debug)]
pub struct Client {
id: AtomicU64,
Expand Down Expand Up @@ -500,32 +523,20 @@ impl Client {
let cmd =
which::which(cmd).map_err(|_| Error::ServerExecutableNotFound(cmd.to_string()))?;

// Redir the server stderr info to a log file, which will be truncated if
// it exists beforehand.
let server_log_dir = dirs::Dirs::base()
.data_dir()
.join("vimclap")
.join("logs")
.join("language_server_stderr");

if !server_log_dir.exists() {
std::fs::create_dir_all(&server_log_dir).ok();
}

let log_path = server_log_dir.join(format!("{name}.log"));
let server_stderr_log = std::fs::File::create(log_path)?;

let mut process = Command::new(cmd)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(server_stderr_log)
.stderr(Stdio::piped())
// Make sure the process is reaped on drop.
// .kill_on_drop(true)
.spawn()?;

let stdin = process.stdin.take().expect("Failed to open stdin");
let stdout = process.stdout.take().expect("Failed to open stdout");
let stderr = process.stderr.take().expect("Failed to open stderr");

spawn_task_stderr(stderr, name.clone());

let payload_sender = spawn_task_stdin(stdin);

Expand Down

0 comments on commit 361ad23

Please sign in to comment.