Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Conversation

@mmanela
Copy link
Contributor

@mmanela mmanela commented Jun 5, 2024

Fixes GRAPH-622

Adds support to the lang file filter for Magik language (lang: Magik). In order to do that we add wrappers around go-enry and update search code to use them. This provides flexibility for us in the future to support other languages that are not in Linguist as well.

This PR does NOT update symbols for Magik (that needs the future scip-ctags work) or udpated code insights (will follow up with that)

Test plan

  • Update unit tests
  • Manually test lang filter

Changelog

  • Added Magik language to language filters (lang:magik)

…support for Magik (and other languages in the future)
@mmanela mmanela marked this pull request as ready for review June 6, 2024 18:53
@mmanela mmanela changed the title feat(graph): Support Magik language file filter in search feat(search): Support Magik language file filter in search Jun 6, 2024
@mmanela mmanela requested a review from jtibshirani June 6, 2024 20:39
Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

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

@mmanela and I chatted offline about adding more tests.

We also decided that this PR will only be scoped to indexed/ unindexed search. In follow up work, we will handle

  • Symbol search (both symbols and Rockskip)
  • Other places that use enry directly, specifically Code Insights

@mmanela mmanela requested a review from jtibshirani June 7, 2024 19:00
@mmanela mmanela merged commit 949a538 into main Jun 11, 2024
@mmanela mmanela deleted the mmanela/GRAPH-622-magik-filter branch June 11, 2024 17:41
Comment on lines +50 to +51
* Languages that are not present in the go-enry library
* and so are not in go-enry either
Copy link
Contributor

@varungandhi-src varungandhi-src Jun 17, 2024

Choose a reason for hiding this comment

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

You could changes this so that:

  • The first mention of go-enry is either Linguist
  • OR you could changes this to say something like "Languages not present in the go-enry library, which we use for language detection in the backend"

Comment on lines +54 to +55
// Not in Linguist and they are not likely to add
'Magik',
Copy link
Contributor

Choose a reason for hiding this comment

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

Linking the PR would've been useful here as context.

Comment on lines +21 to +29
// getLanguagesByExtension is a replacement for enry.GetLanguagesByExtension
// It supports languages that are missing in go-enry
func GetLanguageExtensions(alias string) []string {
if lang, ok := unsupportedByEnryNameToExtensionMap[alias]; ok {
return []string{lang}
}

return enry.GetLanguageExtensions(alias)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you look just below this, we have a function which overrides the behavior of enry's GetLanguagesByExtension. However, the behavior of this function GetLanguageExtensions is not consistent with that, because it doesn't make use of the data in overrideAmbiguousExtensionsMap.

Specifically, if getLanguagesByExtension("foo.json") returns "JSON", then it is not OK for GetLanguageExtensions("OASv2-json") to return ".json" or "json" (https://sourcegraph.com/github.com/github-linguist/linguist/-/blob/lib/linguist/languages.yml?L4750-4760)

var unsupportedByEnryAliasMap = map[string]string{
// Pkl Configuration Language (https://pkl-lang.org/)
"pkl": "Pkl",
// Magik Language
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment does not convey any extra information over the line of code below it; it would make sense to either add a link to help the reader or not have a comment at all.

Comment on lines +89 to +91
// NOTE: Add to linguist on 6/7/24
// can remove once go-enry package updates
// to that linguist version
Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving this purely as a code comment increases the likelihood that it will be forgotten. Instead, you could've added a Go test that the enry list of languages doesn't have this one by doing a map lookup in https://pkg.go.dev/github.com/go-enry/go-enry/[email protected]/data#LanguageInfo

In the code, you can add an easy-to-search for marker, like TODO(id: remove-pkl-special-case) and mention that in the test code so that when someone sees the test failure, they know what other places need updating.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants