Skip to content

Commit

Permalink
don't error on missing grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jun 15, 2024
1 parent 4b26ad6 commit 3ef6aa4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions gopad/editor/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go.gopad.dev/go-tree-sitter"

"go.gopad.dev/gopad/cmd/grammar"

"go.gopad.dev/gopad/gopad/config"
)

Expand Down Expand Up @@ -132,8 +131,10 @@ func LoadLanguages(defaultConfigs embed.FS) error {
if err != nil {
return fmt.Errorf("error loading tree-sitter grammar for %q: %w", name, err)
}
if grammar != nil {
lang.Grammar = grammar
}

lang.Grammar = grammar
}

Check failure on line 138 in gopad/editor/languages.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)

languages = append(languages, lang)
Expand All @@ -155,9 +156,17 @@ func loadTreeSitterGrammar(name string, cfg config.GrammarConfig, defaultConfigs

log.Printf("Loading tree-sitter grammar %q path=%q symbol=%q\n", name, libPath, symbolName)

_, err := os.Stat(libPath)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, nil
}
return nil, fmt.Errorf("error checking lib %q: %w", libPath, err)
}

tsLang, err := sitter.LoadLanguage(symbolName, libPath)
if err != nil {
return nil, fmt.Errorf("error loading tree-sitter language %q path: %q: %w", name, libPath, err)
return nil, fmt.Errorf("error loading lib %q: %w", libPath, err)
}

queriesConfigDir := cfg.QueriesDir
Expand Down
6 changes: 5 additions & 1 deletion gopad/gopad.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ func (g Gopad) CodeBar() string {
}

if language.Config.Grammar != nil {
name = fmt.Sprintf("%s (%s)", name, language.Config.Grammar.Name)
grammarName := language.Config.Grammar.Name
if language.Grammar == nil {
grammarName += " (not loaded)"
}
name = fmt.Sprintf("%s (ts: %s)", name, grammarName)
}

infoLine += fmt.Sprintf("%s | ", name)
Expand Down

0 comments on commit 3ef6aa4

Please sign in to comment.