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

ctags: require scip-ctags to be present #700

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,14 @@ func NewBuilder(opts Options) (*Builder, error) {
finishedShards: map[string]string{},
}

if b.opts.CTagsPath == "" && b.opts.CTagsMustSucceed {
return nil, fmt.Errorf("ctags binary not found, but CTagsMustSucceed set")
}

parserMap, err := ctags.NewParserMap(ctags.ParserBinMap{
ctags.UniversalCTags: b.opts.CTagsPath,
ctags.ScipCTags: b.opts.ScipCTagsPath,
}, b.opts.CTagsMustSucceed)
parserMap, err := ctags.NewParserMap(
ctags.ParserBinMap{
ctags.UniversalCTags: b.opts.CTagsPath,
ctags.ScipCTags: b.opts.ScipCTagsPath,
},
opts.LanguageMap,
b.opts.CTagsMustSucceed,
)

if err != nil {
return nil, err
Expand Down
12 changes: 7 additions & 5 deletions build/ctags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ func ctagsAddSymbolsParserMap(todo []*zoekt.Document, languageMap ctags.Language
continue
}

// If the parser kind is unknown, default to universal-ctags
if parserKind == ctags.UnknownCTags {
parserKind = ctags.UniversalCTags
}

parser := parserMap[parserKind]
if parser == nil {
parser = parserMap[ctags.UniversalCTags]
if parser == nil {
// this happens if CTagsMustSucceed is not true and we didn't find universal-ctags
continue
}
// this happens if CTagsMustSucceed is false and we didn't find the binary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't believe I wrote "not true" instead of "false" in the old code comment.

continue
}

monitor.BeginParsing(doc)
Expand Down
17 changes: 13 additions & 4 deletions ctags/parser_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,23 @@ func StringToParser(str string) CTagsParserType {
type ParserMap map[CTagsParserType]Parser
type ParserBinMap map[CTagsParserType]string

func NewParserMap(bins ParserBinMap, cTagsMustSucceed bool) (ParserMap, error) {
func NewParserMap(bins ParserBinMap, languageMap LanguageMap, cTagsMustSucceed bool) (ParserMap, error) {
parsers := make(ParserMap)

for _, parserType := range []CTagsParserType{UniversalCTags, ScipCTags} {
requiredTypes := []CTagsParserType{UniversalCTags}
for _, parserType := range languageMap {
if parserType == ScipCTags {
requiredTypes = append(requiredTypes, ScipCTags)
break
}
}

for _, parserType := range requiredTypes {
bin := bins[parserType]
if bin != "" {
if bin == "" && cTagsMustSucceed {
return nil, fmt.Errorf("ctags binary not found for %s parser type", ParserToString(parserType))
} else {
parser, err := NewParser(parserType, bin)

if err != nil && cTagsMustSucceed {
return nil, fmt.Errorf("ctags.NewParserMap: %v", err)
}
Expand Down
Loading