-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: code action to add a misspelling to the config file
- Loading branch information
1 parent
df11410
commit 08753d6
Showing
7 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::path::Path; | ||
|
||
use std::path::PathBuf; | ||
|
||
/// Represents a path to a typos_cli config file and, if it contains a configuration file, the file | ||
/// contents | ||
pub struct ConfigFileLocation { | ||
pub path: PathBuf, | ||
pub config: Option<typos_cli::config::Config>, | ||
} | ||
|
||
impl ConfigFileLocation { | ||
pub fn from_dir_or_default(path: &Path) -> ConfigFileLocation { | ||
let directory = if path.is_dir() { | ||
path | ||
} else { | ||
path.parent().unwrap() | ||
}; | ||
ConfigFileLocation::from_dir(directory).unwrap_or_else(|_| ConfigFileLocation { | ||
path: path.to_path_buf(), | ||
config: None, | ||
}) | ||
} | ||
|
||
// copied from typos_cli::config::Config::from_dir with the difference that it shows which | ||
// config file was found of the supported ones. This information is useful when we want to | ||
// modify the config file later on. | ||
pub fn from_dir(dir: &Path) -> anyhow::Result<ConfigFileLocation> { | ||
assert!( | ||
dir.is_dir(), | ||
"Expected a directory that might contain a configuration file" | ||
); | ||
|
||
for file in typos_cli::config::SUPPORTED_FILE_NAMES { | ||
let path = dir.join(file); | ||
if let Ok(Some(config)) = typos_cli::config::Config::from_file(path.as_path()) { | ||
return Ok(ConfigFileLocation { | ||
path, | ||
config: Some(config), | ||
}); | ||
} | ||
} | ||
|
||
Err(anyhow::anyhow!( | ||
"No typos_cli config file found starting from {:?}", | ||
dir | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use config_file_location::ConfigFileLocation; | ||
|
||
use super::config_file_location; | ||
|
||
/// Represents the paths to typos_cli config files that could be used when adding a new ignore | ||
/// rule. The config files may or may not exist. | ||
pub struct ConfigFileSuggestions { | ||
/// The path to a (possible) configuration file in the directory where the LSP server was | ||
/// started. This is always included as the default suggestion. | ||
pub project_root: ConfigFileLocation, | ||
|
||
/// Other configuration files that currently exist in the project. The order is from the closest | ||
/// to the currently open file to the project root. Only existing files are included. | ||
pub config_files: Vec<ConfigFileLocation>, | ||
} |