mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 02:57:52 +08:00
newedit/highlight: hlDep -> Dep.
This commit is contained in:
parent
2029ee781d
commit
4aecff3af1
|
@ -7,14 +7,14 @@ import (
|
|||
"github.com/elves/elvish/styled"
|
||||
)
|
||||
|
||||
// Dependencies for highlighting code.
|
||||
type hlDep struct {
|
||||
// Dep keeps dependencies for highlighting code.
|
||||
type Dep struct {
|
||||
Check func(n *parse.Chunk) error
|
||||
HasCommand func(name string) bool
|
||||
}
|
||||
|
||||
// Highlights a piece of Elvish code.
|
||||
func highlight(code string, hl hlDep) (styled.Text, []error) {
|
||||
func highlight(code string, dep Dep) (styled.Text, []error) {
|
||||
var errors []error
|
||||
|
||||
n, errParse := parse.AsChunk("[interactive]", code)
|
||||
|
@ -26,8 +26,8 @@ func highlight(code string, hl hlDep) (styled.Text, []error) {
|
|||
}
|
||||
}
|
||||
|
||||
if hl.Check != nil {
|
||||
err := hl.Check(n)
|
||||
if dep.Check != nil {
|
||||
err := dep.Check(n)
|
||||
if err != nil && err.(diag.Ranger).Range().From != len(code) {
|
||||
errors = append(errors, err)
|
||||
// TODO: Highlight the region with errors.
|
||||
|
@ -45,10 +45,10 @@ func highlight(code string, hl hlDep) (styled.Text, []error) {
|
|||
|
||||
regionCode := code[r.begin:r.end]
|
||||
transformer := ""
|
||||
if hl.HasCommand != nil && r.typ == commandRegion {
|
||||
if dep.HasCommand != nil && r.typ == commandRegion {
|
||||
// Commands are highlighted differently depending on whether they
|
||||
// are valid.
|
||||
if hl.HasCommand(regionCode) {
|
||||
if dep.HasCommand(regionCode) {
|
||||
transformer = transformerForGoodCommand
|
||||
} else {
|
||||
transformer = transformerForBadCommand
|
||||
|
|
|
@ -43,7 +43,7 @@ func (anyMatcher) Match(tt.RetValue) bool { return true }
|
|||
func TestHighlight(t *testing.T) {
|
||||
any := anyMatcher{}
|
||||
|
||||
dep := hlDep{}
|
||||
dep := Dep{}
|
||||
|
||||
tt.Test(t, tt.Fn("highlight", highlight), tt.Table{
|
||||
Args("ls", dep).Rets(styled.Text{
|
||||
|
@ -78,7 +78,7 @@ func (fakeCheckError) Error() string {
|
|||
|
||||
func TestHighlight_Check(t *testing.T) {
|
||||
var checkError error
|
||||
dep := hlDep{
|
||||
dep := Dep{
|
||||
Check: func(n *parse.Chunk) error {
|
||||
return checkError
|
||||
},
|
||||
|
@ -99,7 +99,7 @@ func TestHighlight_Check(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHighlight_HasCommand(t *testing.T) {
|
||||
dep := hlDep{
|
||||
dep := Dep{
|
||||
HasCommand: func(cmd string) bool {
|
||||
return cmd == "ls"
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@ type Highlighter struct {
|
|||
|
||||
// Get returns the highlighted code and static errors found in the code.
|
||||
func (hl Highlighter) Get(code string) (styled.Text, []error) {
|
||||
return highlight(code, hlDep{hl.Check, hl.HasCommand})
|
||||
return highlight(code, Dep{hl.Check, hl.HasCommand})
|
||||
}
|
||||
|
||||
// LateUpdates returns a channel for notifying late updates.
|
||||
|
|
Loading…
Reference in New Issue
Block a user