Skip to content

Commit

Permalink
Enabling formatting of .cpt files in IDE/VSC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensakejohansson committed Feb 13, 2025
1 parent f1311b2 commit 6f33fff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 15 additions & 1 deletion api/lang/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ func format(request *jsonrpc2.Request) (interface{}, error) {
oldString := getContent(params.TextDocument.URI)
textEdit := createTextEdit(newString, 0, 0, len(strings.Split(oldString, "\n")), len(oldString))
return []lsp.TextEdit{textEdit}, nil
} else if util.IsValidConceptExtension(file) {
conceptsDictionary := gauge.NewConceptDictionary()
_, parseErrs, err := parser.AddConcepts([]string{file}, conceptsDictionary)
if err != nil {
return nil, err
}
if parseErrs != nil {
return nil, fmt.Errorf("failed to format document. Fix all the problems first")
}
conceptMap := formatter.FormatConcepts(conceptsDictionary)
newString := conceptMap[file]
oldString := getContent(params.TextDocument.URI)
textEdit := createTextEdit(newString, 0, 0, len(strings.Split(oldString, "\n")), len(oldString))
return []lsp.TextEdit{textEdit}, nil
}
return nil, fmt.Errorf("failed to format document. %s is not a valid spec file", file)
return nil, fmt.Errorf("failed to format document. %s is not a valid spec/cpt file", file)
}
8 changes: 4 additions & 4 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

"github.com/getgauge/common"
"github.com/getgauge/gauge-proto/go/gauge_messages"
"github.com/getgauge/gauge/config"
"github.com/getgauge/gauge/gauge"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/parser"
"github.com/getgauge/gauge/util"
"github.com/getgauge/gauge/config"
)

const (
Expand Down Expand Up @@ -71,7 +71,7 @@ func FormatStep(step *gauge.Step) string {
} else {
formattedArg = fmt.Sprintf("\"%s\"", parser.GetUnescapedString(argument.Value))
}
text = strings.Replace(text, stripBeforeArg + gauge.ParameterPlaceholder, formattedArg, 1)
text = strings.Replace(text, stripBeforeArg+gauge.ParameterPlaceholder, formattedArg, 1)
}
stepText := ""
if strings.HasSuffix(text, "\n") {
Expand Down Expand Up @@ -126,7 +126,7 @@ func FormatTable(table *gauge.Table) string {
var tableStringBuffer bytes.Buffer

if !config.CurrentGaugeSettings().Format.SkipEmptyLineInsertions {
tableStringBuffer.WriteString("\n")
tableStringBuffer.WriteString("\n")
}

tableStringBuffer.WriteString(fmt.Sprintf("%s|", getRepeatedChars(" ", tableLeftSpacing)))
Expand Down Expand Up @@ -312,4 +312,4 @@ func FormatConceptFilesIn(filesLocation string) {
os.Exit(1)
}
}
}
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// CurrentGaugeVersion represents the current version of Gauge
var CurrentGaugeVersion = &Version{1, 6, 13}
var CurrentGaugeVersion = &Version{1, 6, 14}

// BuildMetadata represents build information of current release (e.g, nightly build information)
var BuildMetadata = ""
Expand Down

0 comments on commit 6f33fff

Please sign in to comment.