mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-08 16:10:29 +09:00
infocomplete: Complete filetypes (follow-up) (#3218)
* infocomplete: Complete filetypes (follow-up) The first shot of the feature unfortunately completed the *.yaml file names instead of the included filetypes. This will be corrected with this follow up. * infocomplete: Correct comment of filetypeComplete according to review hint Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com> --------- Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/micro/v2/pkg/highlight"
|
||||
)
|
||||
|
||||
// This file is meant (for now) for autocompletion in command mode, not
|
||||
@@ -81,9 +82,44 @@ func colorschemeComplete(input string) (string, []string) {
|
||||
func filetypeComplete(input string) (string, []string) {
|
||||
var suggestions []string
|
||||
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntax) {
|
||||
if strings.HasPrefix(f.Name(), input) {
|
||||
suggestions = append(suggestions, f.Name())
|
||||
// We cannot match filetypes just by names of syntax files,
|
||||
// since those names may be different from the actual filetype values
|
||||
// specified inside syntax files (e.g. "c++" filetype in cpp.yaml).
|
||||
// So we need to parse filetype values out of those files.
|
||||
for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
header, err := highlight.MakeHeaderYaml(data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// Prevent duplicated defaults
|
||||
if header.FileType == "off" || header.FileType == "unknown" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(header.FileType, input) {
|
||||
suggestions = append(suggestions, header.FileType)
|
||||
}
|
||||
}
|
||||
headerLoop:
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
header, err := highlight.MakeHeader(data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, v := range suggestions {
|
||||
if v == header.FileType {
|
||||
continue headerLoop
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(header.FileType, input) {
|
||||
suggestions = append(suggestions, header.FileType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user