Repository: JanDeDobbeleer/oh-my-posh
Pull request #1318 (2021-11-26 07:55:01)

feat(language): add configurable extensions
### Prerequisites

- [x] I have read and understood the `CONTRIBUTING` guide
- [x] The commit message follows the [conventional commits][cc] guidelines
- [ ] Tests for the changes have been added (for bug fixes/features)
- [ ] Docs have been added / updated (for bug fixes/features)

### Description

[Description of the change]

<!---

Tips:

If you're not comfortable with working with Git, we're working a guide (https://ohmyposh.dev/docs/contributing_git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary


lnu: the block 
```
 "go.languageServerExperimentalFeatures": {
    "diagnostics": false
  },
```
was causing some issues when loading the go extensions

Patch:
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 74ed8efa..80bad61a 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,9 +1,6 @@
 {
   "go.lintTool": "golangci-lint",
   "go.useLanguageServer": true,
-  "go.languageServerExperimentalFeatures": {
-    "diagnostics": false
-  },
   "go.lintFlags": ["--fast"],
   "go.testOnSave": true,
   "[go]": {
diff --git a/src/properties.go b/src/properties.go
index e7bd2a0a..477a3dd3 100644
--- a/src/properties.go
+++ b/src/properties.go
@@ -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:
diff --git a/src/segment_language.go b/src/segment_language.go
index 37c951b0..6fa84a2c 100644
--- a/src/segment_language.go
+++ b/src/segment_language.go
@@ -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()
 	}


Test patch:
diff --git a/src/segment_node_test.go b/src/segment_node_test.go
index d8c974a0..de14b3ba 100644
--- a/src/segment_node_test.go
+++ b/src/segment_node_test.go
@@ -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,
 				},
 			},
 		}