Module: Textbringer::TreeSitterConfig
- Defined in:
- lib/textbringer/tree_sitter_config.rb
Class Method Summary collapse
- .define_default_faces ⇒ Object
- .dylib_ext ⇒ Object
- .parser_available?(language) ⇒ Boolean
-
.parser_dir ⇒ Object
For backward compatibility, return the first path found.
- .parser_path(language) ⇒ Object
-
.parser_search_paths ⇒ Object
List of directories to search for parsers (in priority order).
- .platform ⇒ Object
Class Method Details
.define_default_faces ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/textbringer/tree_sitter_config.rb', line 65 def define_default_faces Face.define(:comment, foreground: "green") Face.define(:string, foreground: "cyan") Face.define(:keyword, foreground: "yellow") Face.define(:number, foreground: "magenta") Face.define(:constant, foreground: "magenta") Face.define(:function_name, foreground: "blue") Face.define(:type, foreground: "blue") Face.define(:variable, foreground: "white") Face.define(:operator, foreground: "white") Face.define(:punctuation, foreground: "white") Face.define(:builtin, foreground: "cyan") Face.define(:property, foreground: "cyan") end |
.dylib_ext ⇒ Object
13 14 15 |
# File 'lib/textbringer/tree_sitter_config.rb', line 13 def dylib_ext TreeSitter::Platform.dylib_ext end |
.parser_available?(language) ⇒ Boolean
55 56 57 58 59 60 61 62 63 |
# File 'lib/textbringer/tree_sitter_config.rb', line 55 def parser_available?(language) # Normalize language name to handle aliases normalized = TreeSitter::LanguageAliases.normalize(language) filename = "libtree-sitter-#{normalized}#{dylib_ext}" parser_search_paths.any? do |dir| File.exist?(File.join(dir, filename)) end end |
.parser_dir ⇒ Object
For backward compatibility, return the first path found
36 37 38 |
# File 'lib/textbringer/tree_sitter_config.rb', line 36 def parser_dir parser_search_paths.find { |path| Dir.exist?(path) } || parser_search_paths.last end |
.parser_path(language) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/textbringer/tree_sitter_config.rb', line 40 def parser_path(language) # Normalize language name to handle aliases normalized = TreeSitter::LanguageAliases.normalize(language) filename = "libtree-sitter-#{normalized}#{dylib_ext}" # Search for parser in search paths parser_search_paths.each do |dir| path = File.join(dir, filename) return path if File.exist?(path) end # Return default path if not found File.join(parser_search_paths.last, filename) end |
.parser_search_paths ⇒ Object
List of directories to search for parsers (in priority order)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/textbringer/tree_sitter_config.rb', line 18 def parser_search_paths paths = [] # 1. Custom path specified in CONFIG (highest priority) if defined?(CONFIG) && CONFIG[:tree_sitter_parser_dir] paths << CONFIG[:tree_sitter_parser_dir] end # 2. ~/.textbringer/parsers/{platform} (user-level shared) paths << File.("~/.textbringer/parsers/#{platform}") # 3. parsers/{platform} inside the gem (default) paths << File.("../../../parsers/#{platform}", __FILE__) paths end |
.platform ⇒ Object
9 10 11 |
# File 'lib/textbringer/tree_sitter_config.rb', line 9 def platform TreeSitter::Platform.platform end |