-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Refactor code_indexer to use an SearchOptions struct for PerformSearch #29724
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
Changes from 4 commits
ac713c9
fc52fce
e7bd0e2
1a0df0e
5c0bbb1
5b5e184
5631d3e
de98310
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ type ResultLine struct { | |
|
||
type SearchResultLanguages = internal.SearchResultLanguages | ||
|
||
type SearchOptions = internal.SearchOptions | ||
|
||
func indices(content string, selectionStartIndex, selectionEndIndex int) (int, int) { | ||
startIndex := selectionStartIndex | ||
numLinesBefore := 0 | ||
|
@@ -125,12 +127,12 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res | |
|
||
// PerformSearch perform a search on a repository | ||
// if isFuzzy is true set the Damerau-Levenshtein distance from 0 to 2 | ||
func PerformSearch(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int, []*Result, []*internal.SearchResultLanguages, error) { | ||
if len(keyword) == 0 { | ||
func PerformSearch(ctx context.Context, opts *internal.SearchOptions) (int, []*Result, []*internal.SearchResultLanguages, error) { | ||
if opts == nil || len(opts.Keyword) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not be nil ... but better not panic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If it shouldn't be nil, why not report the errors in development stage? Just by a panic. I really dislike hiding errors. It makes it more difficult to debug some bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NO we should not panic if we can arange it. To hope for stacktraces to get reported as "linting" methode is wrong !!! But what we can do is create a proper error to check against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NO, why it would panic if there is no bug in code? Golang library itself panics a lot if something is totally wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't think we should check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me check (again) what comsumers this func has ... and also introduce a proper error instead of a ignore on keyword=="" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm ... I only mean
Golang has a very bad error system, TBH I have been tired of writing a lot of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you wana create a pull? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it has been merged, I think it could be left there as-is, no good no harm. |
||
return 0, nil, nil, nil | ||
} | ||
|
||
total, results, resultLanguages, err := (*globalIndexer.Load()).Search(ctx, repoIDs, language, keyword, page, pageSize, isFuzzy) | ||
total, results, resultLanguages, err := (*globalIndexer.Load()).Search(ctx, opts) | ||
if err != nil { | ||
return 0, nil, nil, err | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.