Skip to content

Commit

Permalink
fix: use to_file_path() instead of path
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jan 2, 2024
1 parent 978b7ab commit dc2b12c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,16 @@ impl LanguageServer for Backend {
impl Backend {
async fn on_change(&self, params: TextDocumentItem) {
let uri = params.uri.clone();
let fp = uri.to_file_path();

let has_cli = self.cli.is_installed();

self.update(params.clone());
if self.cli.is_installed() {
match self.cli.run(uri.path(), self.config_path(), self.config_filter()) {
if has_cli && fp.is_ok() {
match self
.cli
.run(fp.unwrap(), self.config_path(), self.config_filter())
{
Ok(result) => {
let mut diagnostics = Vec::new();
for (_, v) in result.iter() {
Expand All @@ -406,6 +412,17 @@ impl Backend {
};
}
}
} else if !has_cli {
self.client
.log_message(MessageType::WARNING, "Vale CLI not installed!")
.await;
} else {
self.client
.log_message(
MessageType::ERROR,
format!("File path error: {:?}", fp.err()),
)
.await;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ impl ValeManager {
/// If `filter` is not empty, it will be passed to Vale as `--filter`.
pub(crate) fn run(
&self,
fp: &str,
fp: PathBuf,
config_path: String,
filter: String,
) -> Result<HashMap<String, Vec<ValeAlert>>, Error> {
let mut args = self.args.clone();
let cwd = path::Path::new(fp).parent().unwrap();
let cwd = fp.parent().unwrap();

if config_path != "" {
args.push(format!("--config={}", config_path));
}
if filter != "" {
args.push(format!("--filter={}", filter));
}
args.push(fp.to_string());
args.push(fp.as_path().display().to_string());

let exe = self.exe_path(false)?;
let out = Command::new(exe.as_os_str())
Expand Down

0 comments on commit dc2b12c

Please sign in to comment.