Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: xtask themelint #3234

Merged
merged 36 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
324c11a
feat: cargo xtask themelint <theme>
AlexanderBrevig Jul 28, 2022
5a09b77
fix: add docs and print json error status
AlexanderBrevig Jul 28, 2022
a931e61
fix: refactor paths -> path
AlexanderBrevig Jul 29, 2022
d4946fa
Merge remote-tracking branch 'upstream/master' into xtask-themelint
AlexanderBrevig Jul 30, 2022
b90f318
fix: remove unused function
AlexanderBrevig Jul 30, 2022
a11bc22
fix: only report one err per scope (ui.statusline is reported if none…
AlexanderBrevig Jul 31, 2022
b4edea4
fix: save work for later
AlexanderBrevig Aug 4, 2022
80f7b1d
Merge remote-tracking branch 'origin/master' into xtask-themelint
AlexanderBrevig Aug 25, 2022
7ccb816
fix: finally decided on a design
AlexanderBrevig Aug 25, 2022
10cda98
fix: ready for discussion
AlexanderBrevig Aug 25, 2022
943c421
fix: better rules
AlexanderBrevig Aug 27, 2022
16a5f87
fix: lint precision
AlexanderBrevig Aug 29, 2022
336e901
fix: String -> &'static str
AlexanderBrevig Aug 29, 2022
90ca345
fix: allowlist not denylist for file type
AlexanderBrevig Aug 29, 2022
d160366
fix: add missing and indication of what's needed
AlexanderBrevig Aug 29, 2022
6ffba6b
fix: copy pasteable errors
AlexanderBrevig Aug 29, 2022
237f706
fix: use Loader:read_names
AlexanderBrevig Aug 29, 2022
50662cf
Update xtask/src/helpers.rs
AlexanderBrevig Aug 29, 2022
af2011d
fix: remove into and clone for str
AlexanderBrevig Aug 31, 2022
0632c3f
Update book/src/themes.md
AlexanderBrevig Aug 31, 2022
b2f6540
fix: better lint output
AlexanderBrevig Sep 1, 2022
1a8d812
fix: cleaner logic for lint reporting
AlexanderBrevig Sep 1, 2022
1cf35e7
style: use explicit imports
AlexanderBrevig Sep 1, 2022
917aec4
Pascal support (#3542)
ath3 Aug 25, 2022
464d7c5
fix: add difference check for statusline normal,insert,select
AlexanderBrevig Sep 5, 2022
f64c587
fix: fg for whitespace and early exit if and one is ok
AlexanderBrevig Sep 5, 2022
726f85b
chore: cleaning up, no idea how these got here or how this will look
AlexanderBrevig Sep 9, 2022
91bb2f5
chore: revert from older commit?
AlexanderBrevig Sep 9, 2022
4ce09f7
refactor: use static fn to equalize api between difference and existance
AlexanderBrevig Sep 9, 2022
4c157aa
Merge branch 'master' into xtask-themelint
AlexanderBrevig Sep 9, 2022
a264aef
refactor: querycheck and clippy
AlexanderBrevig Sep 9, 2022
434c35d
refactor: clippy fixes
AlexanderBrevig Sep 9, 2022
11840be
fix: query-check behaves as before
AlexanderBrevig Sep 9, 2022
6e2b7b3
fix: error with x of y message, not total count
AlexanderBrevig Sep 11, 2022
886206f
fix: consistent reporting and less mutable state
AlexanderBrevig Sep 14, 2022
0f0282f
fix: selection difference ref #3942 ref #1833
AlexanderBrevig Sep 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,10 @@ These scopes are used for theming the editor interface.
| `diagnostic.warning` | Diagnostics warning (editing area) |
| `diagnostic.error` | Diagnostics error (editing area) |

You can check compliance to spec with

```shell
cargo xtask themelint onedark # replace onedark with <name>
```

[editor-section]: ./configuration.md#editor-section
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ edition = "2021"
[dependencies]
helix-term = { version = "0.6", path = "../helix-term" }
helix-core = { version = "0.6", path = "../helix-core" }
helix-view = { version = "0.6", path = "../helix-view" }
helix-loader = { version = "0.6", path = "../helix-loader" }
toml = "0.5"
117 changes: 117 additions & 0 deletions xtask/src/docgen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use crate::helpers;
use crate::path;
use crate::DynError;

use helix_term::commands::TYPABLE_COMMAND_LIST;
use helix_term::health::TsFeature;
use std::fs;

pub const TYPABLE_COMMANDS_MD_OUTPUT: &str = "typable-cmd.md";
pub const LANG_SUPPORT_MD_OUTPUT: &str = "lang-support.md";

fn md_table_heading(cols: &[String]) -> String {
let mut header = String::new();
header += &md_table_row(cols);
header += &md_table_row(&vec!["---".to_string(); cols.len()]);
header
}

fn md_table_row(cols: &[String]) -> String {
format!("| {} |\n", cols.join(" | "))
}

fn md_mono(s: &str) -> String {
format!("`{}`", s)
}

pub fn typable_commands() -> Result<String, DynError> {
let mut md = String::new();
md.push_str(&md_table_heading(&[
"Name".to_owned(),
"Description".to_owned(),
]));

let cmdify = |s: &str| format!("`:{}`", s);

for cmd in TYPABLE_COMMAND_LIST {
let names = std::iter::once(&cmd.name)
.chain(cmd.aliases.iter())
.map(|a| cmdify(a))
.collect::<Vec<_>>()
.join(", ");

let doc = cmd.doc.replace('\n', "<br>");

md.push_str(&md_table_row(&[names.to_owned(), doc.to_owned()]));
}

Ok(md)
}

pub fn lang_features() -> Result<String, DynError> {
let mut md = String::new();
let ts_features = TsFeature::all();

let mut cols = vec!["Language".to_owned()];
cols.append(
&mut ts_features
.iter()
.map(|t| t.long_title().to_string())
.collect::<Vec<_>>(),
);
cols.push("Default LSP".to_owned());

md.push_str(&md_table_heading(&cols));
let config = helpers::lang_config();

let mut langs = config
.language
.iter()
.map(|l| l.language_id.clone())
.collect::<Vec<_>>();
langs.sort_unstable();

let mut ts_features_to_langs = Vec::new();
for &feat in ts_features {
ts_features_to_langs.push((feat, helpers::ts_lang_support(feat)));
}

let mut row = Vec::new();
for lang in langs {
let lc = config
.language
.iter()
.find(|l| l.language_id == lang)
.unwrap(); // lang comes from config
row.push(lc.language_id.clone());

for (_feat, support_list) in &ts_features_to_langs {
row.push(
if support_list.contains(&lang) {
"✓"
} else {
""
}
.to_owned(),
);
}
row.push(
lc.language_server
.as_ref()
.map(|s| s.command.clone())
.map(|c| md_mono(&c))
.unwrap_or_default(),
);

md.push_str(&md_table_row(&row));
row.clear();
}

Ok(md)
}

pub fn write(filename: &str, data: &str) {
let error = format!("Could not write to {}", filename);
let path = path::book_gen().join(filename);
fs::write(path, data).expect(&error);
}
44 changes: 44 additions & 0 deletions xtask/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::path::{Path, PathBuf};

use crate::path;
use helix_core::syntax::Configuration as LangConfig;
use helix_term::health::TsFeature;

/// Get the list of languages that support a particular tree-sitter
/// based feature.
pub fn ts_lang_support(feat: TsFeature) -> Vec<String> {
let queries_dir = path::ts_queries();

find_files(&queries_dir, feat.runtime_filename())
.iter()
.map(|f| {
// .../helix/runtime/queries/python/highlights.scm
let tail = f.strip_prefix(&queries_dir).unwrap(); // python/highlights.scm
let lang = tail.components().next().unwrap(); // python
lang.as_os_str().to_string_lossy().to_string()
})
.collect()
}

// naive implementation, but suffices for our needs
pub fn find_files(dir: &Path, filename: &str) -> Vec<PathBuf> {
std::fs::read_dir(dir)
.unwrap()
.filter_map(|entry| {
let path = entry.ok()?.path();
if path.is_dir() {
Some(find_files(&path, filename))
} else if path.file_name()?.to_string_lossy() == filename {
Some(vec![path])
} else {
None
}
})
.flatten()
.collect()
}

pub fn lang_config() -> LangConfig {
let bytes = std::fs::read(path::lang_config()).unwrap();
toml::from_slice(&bytes).unwrap()
}
Loading