feat(language): add configurable extensions

This commit is contained in:
lnu 2021-11-26 08:54:16 +01:00 committed by Jan De Dobbeleer
parent 5256c90531
commit 435e362256
4 changed files with 21 additions and 6 deletions

View file

@ -1,9 +1,6 @@
{
"go.lintTool": "golangci-lint",
"go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
"diagnostics": false
},
"go.lintFlags": ["--fast"],
"go.testOnSave": true,
"[go]": {

View file

@ -127,6 +127,17 @@ func (p properties) getKeyValueMap(property Property, defaultValue map[string]st
return keyValues
}
func (p properties) getStringArray(property Property, defaultValue []string) []string {
val, found := p[property]
if !found {
return defaultValue
}
keyValues := parseStringArray(val)
return keyValues
}
func parseStringArray(param interface{}) []string {
switch v := param.(type) {
default:

View file

@ -25,7 +25,8 @@ type cmd struct {
executable string
args []string
regex string
version *version
version
}
func (c *cmd) parse(versionInfo string) error {
@ -33,7 +34,7 @@ func (c *cmd) parse(versionInfo string) error {
if len(values) == 0 {
return errors.New("cannot parse version string")
}
c.version = &version{}
c.version.Full = values["version"]
c.version.Major = values["major"]
c.version.Minor = values["minor"]
@ -98,6 +99,8 @@ const (
EnableVersionMismatch Property = "enable_version_mismatch"
// HomeEnabled displays the segment in the HOME folder or not
HomeEnabled Property = "home_enabled"
// LanguageExtensions the list of extensions to validate
LanguageExtensions Property = "extensions"
)
func (l *language) string() string {
@ -151,6 +154,9 @@ func (l *language) string() string {
}
func (l *language) enabled() bool {
// override default extensions if needed
l.extensions = l.props.getStringArray(LanguageExtensions, l.extensions)
inHomeDir := func() bool {
return l.env.getcwd() == l.env.homeDir()
}

View file

@ -31,11 +31,12 @@ func TestNodeMatchesVersionFile(t *testing.T) {
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("getFileContent", ".nvmrc").Return(tc.RCVersion)
node := &node{
language: &language{
env: env,
activeCommand: &cmd{
version: &nodeVersion,
version: nodeVersion,
},
},
}