Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling formatting of .cpt files in IDE/VSC. #2700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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