Skip to content

Commit

Permalink
hiding debug codelens if lsp is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
nehashri committed May 2, 2018
1 parent 765d3e7 commit c23df9f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
14 changes: 8 additions & 6 deletions api/lang/codeLens.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ func getExecutionCodeLenses(params lsp.CodeLensParams) (interface{}, error) {
var codeLenses []lsp.CodeLens
runCodeLens := createCodeLens(spec.Heading.LineNo-1, runSpecCodeLens, executeCommand, getExecutionArgs(spec.FileName))
codeLenses = append(codeLenses, runCodeLens)
debugCodeLens := createCodeLens(spec.Heading.LineNo-1, debugSpecCodeLens, debugCommand, getExecutionArgs(spec.FileName))
codeLenses = append(codeLenses, debugCodeLens)
if lRunner.lspID != "" {
debugCodeLens := createCodeLens(spec.Heading.LineNo-1, debugSpecCodeLens, debugCommand, getExecutionArgs(spec.FileName))
codeLenses = append(codeLenses, debugCodeLens)
}
if spec.DataTable.IsInitialized() {
codeLenses = append(codeLenses, getDataTableLenses(spec)...)
}
return append(getScenarioCodeLenses(spec), codeLenses...), nil

}

func getReferenceCodeLenses(params lsp.CodeLensParams) (interface{}, error) {
Expand Down Expand Up @@ -127,9 +128,10 @@ func getScenarioCodeLenses(spec *gauge.Specification) []lsp.CodeLens {
args := getExecutionArgs(fmt.Sprintf("%s:%d", spec.FileName, sce.Heading.LineNo))
lens := createCodeLens(sce.Heading.LineNo-1, runScenarioCodeLens, executeCommand, args)
lenses = append(lenses, lens)
debugCodeLens := createCodeLens(sce.Heading.LineNo-1, debugScenarioCodeLens, debugCommand, args)
lenses = append(lenses, debugCodeLens)

if lRunner.lspID != "" {
debugCodeLens := createCodeLens(sce.Heading.LineNo-1, debugScenarioCodeLens, debugCommand, args)
lenses = append(lenses, debugCodeLens)
}
}
return lenses
}
Expand Down
54 changes: 54 additions & 0 deletions api/lang/codeLens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Scenario Heading
* Step text`

lRunner.lspID = "python"
openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}
openFilesCache.add("foo.spec", specText)

Expand Down Expand Up @@ -117,6 +118,7 @@ Another Scenario
* another step
`

lRunner.lspID = "python"
openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}
openFilesCache.add("foo.spec", specText)

Expand Down Expand Up @@ -302,3 +304,55 @@ Scenario Heading
t.Errorf("want: `%v`,\n got: `%v`", want, got)
}
}

func TestGetDebugCodeLensForNonLspRunner(t *testing.T) {
specText := `Specification Heading
=====================
Scenario Heading
----------------
* Step text`

lRunner.lspID = ""
openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}
openFilesCache.add("foo.spec", specText)

b, _ := json.Marshal(lsp.CodeLensParams{TextDocument: lsp.TextDocumentIdentifier{URI: "foo.spec"}})
p := json.RawMessage(b)

got, err := codeLenses(&jsonrpc2.Request{Params: &p})
if err != nil {
t.Errorf("Expected error to be nil. got : %s", err.Error())
}

specCodeLens := lsp.CodeLens{
Command: lsp.Command{
Command: "gauge.execute",
Title: "Run Spec",
Arguments: getExecutionArgs("foo.spec"),
},
Range: lsp.Range{
Start: lsp.Position{0, 0},
End: lsp.Position{0, 8},
},
}

scenCodeLens := lsp.CodeLens{
Command: lsp.Command{
Command: "gauge.execute",
Title: "Run Scenario",
Arguments: getExecutionArgs("foo.spec:4"),
},
Range: lsp.Range{
Start: lsp.Position{3, 0},
End: lsp.Position{3, 12},
},
}

want := []lsp.CodeLens{scenCodeLens, specCodeLens}

if !reflect.DeepEqual(got, want) {
t.Errorf("want: `%v`,\n got: `%v`", want, got)
}
}

0 comments on commit c23df9f

Please sign in to comment.