How to configure cpp syntax highlighting with tree-sitter mode? #1094
Unanswered
yangchaoFree
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have configured syntax highlighting in config. json:
..
"cpp": {
"extensions": [
"cpp",
"cc",
"cxx",
"hpp",
"hh",
"hxx"
],
"filenames": [],
"grammar": "cpp",
"comment_prefix": "//",
"auto_indent": true,
"highlighter": "tree-sitter",
"textmate_grammar": null,
"show_whitespace_tabs": true,
"use_tabs": false
},
..
But after tracking the code, it was found that the syntax highlighting was actually using HighlighterPreference:: TextMate:
During the initialization process, call stack:
for_file_with_languages()
->for_file_with_languages_and_preference()
->.. Self::textmate_for_file_with_languages(path, registry, languages) //set texmate mode
From the source code, it can be seen that the fixed setting is textmate mode:
pub fn for_file_with_languages(
path: &Path,
registry: &GrammarRegistry,
languages: &std::collections::HashMap<String, crate::config::LanguageConfig>,
) -> Self {
Self::for_file_with_languages_and_preference(
path,
registry,
languages,
HighlighterPreference::Auto, **// set Auto mode; **
)
}
pub fn for_file_with_languages_and_preference(
path: &Path,
registry: &GrammarRegistry,
languages: &std::collections::HashMap<String, crate::config::LanguageConfig>,
preference: HighlighterPreference,
) -> Self {
match preference {
// Auto now defaults to TextMate for highlighting (syntect has broader coverage)
// but still detects tree-sitter language for indentation/semantic features
HighlighterPreference::Auto | HighlighterPreference::TextMate => {
Self::textmate_for_file_with_languages(path, registry, languages) // will go to here
}
HighlighterPreference::TreeSitter => {
if let Some(lang) = Language::from_path(path) {
if let Ok(highlighter) = Highlighter::new(lang) {
return Self::TreeSitter(Box::new(highlighter));
}
}
Self::None
}
}
}
Beta Was this translation helpful? Give feedback.
All reactions