feat(language): enable in home dir when always_enabled

resolves #649
This commit is contained in:
Jan De Dobbeleer 2021-04-17 13:28:06 +02:00 committed by Jan De Dobbeleer
parent 6a6715faec
commit c98c1b5425
2 changed files with 38 additions and 2 deletions

View file

@ -116,11 +116,14 @@ func (l *language) string() string {
}
func (l *language) enabled() bool {
if l.env.getcwd() == l.env.homeDir() {
inHomeDir := func() bool {
return l.env.getcwd() == l.env.homeDir()
}
displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
if inHomeDir() && displayMode != DisplayModeAlways {
return false
}
l.loadLanguageContext()
displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
switch displayMode {
case DisplayModeAlways:
return true

View file

@ -438,6 +438,39 @@ func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
assert.Equal(t, "[1.3.307](https://unicor.org/doc/1)", lang.string())
}
func TestLanguageEnabledInHome(t *testing.T) {
cases := []struct {
Case string
DisplayMode string
ExpectedEnabled bool
}{
{Case: "Always enabled", DisplayMode: DisplayModeAlways, ExpectedEnabled: true},
{Case: "Context disabled", DisplayMode: DisplayModeContext, ExpectedEnabled: false},
}
for _, tc := range cases {
props := map[Property]interface{}{
DisplayMode: tc.DisplayMode,
}
args := &languageArgs{
commands: []*cmd{
{
executable: "uni",
args: []string{"--version"},
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
},
},
extensions: []string{uni, corn},
enabledExtensions: []string{corn},
enabledCommands: []string{"corn"},
version: universion,
properties: props,
inHome: true,
}
lang := bootStrapLanguageTest(args)
assert.Equal(t, tc.ExpectedEnabled, lang.enabled(), tc.Case)
}
}
func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) {
props := map[Property]interface{}{
EnableHyperlink: true,