refactor(language): remap context to files

This commit is contained in:
Jan De Dobbeleer 2021-01-12 20:37:14 +01:00 committed by Jan De Dobbeleer
parent 31c77af58f
commit 890f9cde1b
7 changed files with 16 additions and 16 deletions

View file

@ -29,4 +29,4 @@ Display the currently active golang version when a folder contains `.go` files.
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: The segment is always displayed
- `context`: The segment is only displayed when *.go or go.mod files are present (default)
- `files`: The segment is only displayed when `*.go` or `go.mod` files are present (default)

View file

@ -29,4 +29,4 @@ Display the currently active julia version when a folder contains `.jl` files.
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: The segment is always displayed
- `context`: The segment is only displayed when *.jl files are present (default)
- `files`: The segment is only displayed when `*.jl` files are present (default)

View file

@ -29,4 +29,4 @@ Display the currently active node version when a folder contains `.js` or `.ts`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: The segment is always displayed
- `context`: The segment is only displayed when *.js, *.ts or package.json files are present (default)
- `files`: The segment is only displayed when `*.js`, `*.ts` or package.json files are present (default)

View file

@ -31,4 +31,4 @@ Supports conda, virtualenv and pyenv.
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: The segment is always displayed
- `context`: The segment is only displayed when *.py or *.ipynb files are present (default)
- `files`: The segment is only displayed when `*.py` or `*.ipynb` files are present (default)

View file

@ -15,12 +15,12 @@ type language struct {
}
const (
// DisplayModeProperty sets the display mode (always, when_in_context, never)
DisplayModeProperty Property = "display_mode"
// DisplayMode sets the display mode (always, when_in_context, never)
DisplayMode Property = "display_mode"
// DisplayModeAlways displays the segment always
DisplayModeAlways string = "always"
// DisplayModeContext displays the segment when the current folder contains certain extensions
DisplayModeContext string = "context"
// DisplayModeFiles displays the segment when the current folder contains certain extensions
DisplayModeFiles string = "files"
// MissingCommandTextProperty sets the text to display when the command is not present in the system
MissingCommandTextProperty Property = "missing_command_text"
// MissingCommandText displays empty string by default
@ -41,21 +41,21 @@ func (l *language) string() string {
}
func (l *language) enabled() bool {
displayMode := l.props.getString(DisplayModeProperty, DisplayModeContext)
displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
displayVersion := l.props.getBool(DisplayVersion, true)
switch displayMode {
case DisplayModeAlways:
return (!displayVersion || l.hasCommand())
case DisplayModeContext:
case DisplayModeFiles:
fallthrough
default:
return l.isInContext() && (!displayVersion || l.hasCommand())
return l.hasLanguageFiles() && (!displayVersion || l.hasCommand())
}
}
// isInContext will return true at least one file matching the extensions is found
func (l *language) isInContext() bool {
// hasLanguageFiles will return true at least one file matching the extensions is found
func (l *language) hasLanguageFiles() bool {
for i, extension := range l.extensions {
if l.env.hasFiles(extension) {
break

View file

@ -45,8 +45,8 @@ func bootStrapLanguageTest(args *languageArgs) *language {
}
props := &properties{
values: map[Property]interface{}{
DisplayVersion: args.displayVersion,
DisplayModeProperty: args.displayMode,
DisplayVersion: args.displayVersion,
DisplayMode: args.displayMode,
},
}
if args.missingCommandText != "" {

View file

@ -21,7 +21,7 @@
"type": "string",
"title": "Display Mode",
"description": "Determines whether the segment is displayed always or only if a file matching the extensions are present in the current folder",
"enum": ["always", "context", "never"],
"enum": ["always", "files"],
"default": "context"
},
"missing_command_text": {