How to use codeActions method of lang Package

Best Gauge code snippet using lang.codeActions

src-mod.go

Source:src-mod.go Github

copy

Full Screen

1package z2import (3 "strings"4 "github.com/go-leap/fs"5)6type ISrcMod interface {7 IMenuItems8 CodeActions(*SrcLens) []EditorAction9 DoesStdoutWithFilePathArg(*Tool) bool10 KnownFormatters() Tools11 RunRenamer(*SrcLens, string) SrcLenses12 RunFormatter(*Tool, string, *SrcFormattingClientPrefs, string, string) (string, string)13}14func (me *SrcModEdits) dropConflictingEdits() (droppedOffenders []SrcModEdit) {15 all := *me16 for i := 0; i < len(all); i++ {17 for disedit, j := all[i], i+1; j < len(all); j++ {18 if datedit := all[j]; disedit.At.overlapsWith(datedit.At) {19 droppedOffenders = append(droppedOffenders, all[j])20 pref, suff := all[:j], all[j+1:]21 j, all = j-1, append(pref, suff...)22 }23 }24 }25 *me = all26 return27}28func (me SrcModEdits) Len() int { return len(me) }29func (me SrcModEdits) Swap(i int, j int) { me[i], me[j] = me[j], me[i] }30func (me SrcModEdits) Less(i int, j int) bool {31 return me[i].At.Start.isSameOrGreaterThan(&me[j].At.End)32}33func (*SrcModEdits) lensForNewEdit(srcFilePath string) *SrcLens {34 var lens = SrcLens{SrcLoc: SrcLoc{FilePath: srcFilePath}}35 lens.EnsureSrcFull()36 return &lens37}38func (me *SrcModEdits) AddDeleteLine(srcFilePath string, lineAt *SrcPos) {39 lens := me.lensForNewEdit(srcFilePath)40 lens.Pos = lineAt41 edit := SrcModEdit{At: &SrcRange{}}42 bo := lens.Byte0OffsetForPos(lens.Pos)43 bo = strings.LastIndex(lens.Txt[:bo], "\n") + 144 edit.At.Start.Off = lens.Rune1OffsetForByte0Offset(bo)45 bo2 := strings.IndexRune(lens.Txt[bo:], '\n') + 146 edit.At.End.Off = lens.Rune1OffsetForByte0Offset(bo + bo2)47 *me = append(*me, edit)48}49func (me *SrcModEdits) AddInsert(srcFilePath string, atPos func(*SrcLens, *SrcPos) string) {50 lens := me.lensForNewEdit(srcFilePath)51 edit := SrcModEdit{At: &SrcRange{}}52 if ins := atPos(lens, &edit.At.Start); ins != "" {53 edit.Val = ins54 *me = append(*me, edit)55 }56}57type SrcModBase struct {58 cmdFmtSetDef *MenuItem59 cmdFmtRunOnFile *MenuItem60 cmdFmtRunOnSel *MenuItem61 Impl ISrcMod62}63type SrcFormattingClientPrefs struct {64 InsertSpaces *bool65 TabSize *int66}67func (me *SrcModBase) Init() {68 me.cmdFmtSetDef = &MenuItem{69 IpcID: IPCID_SRCMOD_FMT_SETDEFMENU,70 Title: Strf("Choose Default %s Formatter", Lang.Title),71 Desc: "Specify your preferred default source formatter",72 }73 me.cmdFmtRunOnFile = &MenuItem{74 IpcID: IPCID_SRCMOD_FMT_RUNONFILE,75 Title: "Format Document",76 }77 me.cmdFmtRunOnSel = &MenuItem{78 IpcID: IPCID_SRCMOD_FMT_RUNONSEL,79 Title: "Format Selection",80 }81}82func (me *SrcModBase) menuItems(srcLens *SrcLens) (cmds MenuItems) {83 if srcLens != nil {84 srcfilepath, hint := srcLens.FilePath, "("+me.cmdFmtSetDef.Desc+" first)"85 if me.hasFormatter() {86 if hint = "➜ using "; me.isFormatterCustom() {87 hint += "'" + Prog.Cfg.FormatterProg + "' like "88 }89 hint += "'" + Prog.Cfg.FormatterName + "'"90 }91 if isfp := srcfilepath != ""; isfp || srcLens.Txt != "" {92 srcfilepath = Lang.Workspace.PrettyPath(srcfilepath)93 if me.cmdFmtRunOnFile.Desc, me.cmdFmtRunOnFile.Hint = srcfilepath, hint; !isfp {94 me.cmdFmtRunOnFile.Desc = srcLens.Txt95 }96 cmds = append(cmds, me.cmdFmtRunOnFile)97 }98 if srcLens.Str != "" {99 me.cmdFmtRunOnSel.Desc = srcLens.Str100 me.cmdFmtRunOnSel.Hint = hint101 cmds = append(cmds, me.cmdFmtRunOnSel)102 }103 }104 if me.cmdFmtSetDef.Hint = "(none)"; me.hasFormatter() {105 if me.cmdFmtSetDef.Hint = "'" + Prog.Cfg.FormatterName + "'"; me.isFormatterCustom() {106 me.cmdFmtSetDef.Hint += "-compatible '" + Prog.Cfg.FormatterProg + "'"107 }108 }109 me.cmdFmtSetDef.Hint = "Current: " + me.cmdFmtSetDef.Hint110 cmds = append(cmds, me.cmdFmtSetDef)111 return112}113func (*SrcModBase) MenuCategory() string {114 return "Formatting"115}116func (*SrcModBase) CodeActions(srcLens *SrcLens) (all []EditorAction) {117 return118}119func (*SrcModBase) DoesStdoutWithFilePathArg(*Tool) bool { return false }120func (me *SrcModBase) KnownFormatters() Tools { return nil }121func (*SrcModBase) RunFormatter(*Tool, string, *SrcFormattingClientPrefs, string, string) (string, string) {122 panic(Strf("Formatting not yet implemented for %s.", Lang.Title))123}124func (*SrcModBase) RunRenamer(srcLens *SrcLens, newName string) (all SrcLenses) {125 panic(Strf("Rename not yet implemented for %s.", Lang.Title))126}127func (*SrcModBase) hasFormatter() bool {128 return Prog.Cfg.FormatterName != ""129}130func (*SrcModBase) isFormatterCustom() bool {131 return Prog.Cfg.FormatterProg != "" && Prog.Cfg.FormatterProg != Prog.Cfg.FormatterName132}133func (me *SrcModBase) dispatch(req *IpcReq, resp *IpcResp) bool {134 switch req.IpcID {135 case IPCID_SRCMOD_FMT_SETDEFMENU:136 me.onSetDefMenu(req, resp)137 case IPCID_SRCMOD_FMT_SETDEFPICK:138 me.onSetDefPick(req, resp)139 case IPCID_SRCMOD_FMT_RUNONFILE, IPCID_SRCMOD_FMT_RUNONSEL:140 me.onRunFormatter(req, resp)141 case IPCID_SRCMOD_RENAME:142 me.onRename(req, resp)143 case IPCID_SRCMOD_ACTIONS:144 me.onActions(req, resp)145 default:146 return false147 }148 return true149}150func (me *SrcModBase) onActions(req *IpcReq, resp *IpcResp) {151 resp.SrcActions = me.Impl.CodeActions(req.SrcLens)152}153func (me *SrcModBase) onRename(req *IpcReq, resp *IpcResp) {154 newname, _ := req.IpcArgs.(string)155 if newname == "" {156 resp.ErrMsg = "Rename: missing new-name"157 } else {158 resp.SrcMods = me.Impl.RunRenamer(req.SrcLens, newname)159 }160}161func (me *SrcModBase) onRunFormatter(req *IpcReq, resp *IpcResp) {162 optraw, _ := req.IpcArgs.(map[string]interface{})163 var prefs *SrcFormattingClientPrefs164 if optraw != nil {165 tabSize, ok1 := optraw["tabSize"].(float64)166 insertSpaces, ok2 := optraw["insertSpaces"].(bool)167 if ok1 || ok2 {168 if prefs = (&SrcFormattingClientPrefs{}); ok2 {169 prefs.InsertSpaces = &insertSpaces170 }171 if tabsize := int(tabSize); ok1 {172 prefs.TabSize = &tabsize173 }174 }175 } else {176 resp.Menu = &MenuResponse{}177 }178 formatter := me.Impl.KnownFormatters().byName(Prog.Cfg.FormatterName)179 if formatter == nil {180 if resp.Menu == nil {181 resp.ErrMsg = "Select a Default Formatter first via the Zentient Main Menu."182 } else {183 resp.Menu.NoteWarn = "Select a Default Formatter first, either via the Zentient Main Menu or:"184 resp.IpcID = IPCID_SRCMOD_FMT_SETDEFMENU185 resp.Menu.UxActionLabel = Strf("Pick your preferred Zentient default %s formatter...", Lang.Title)186 }187 return188 }189 srcfilepath := req.SrcLens.FilePath190 withfilepathcmdarg := me.Impl.DoesStdoutWithFilePathArg(formatter)191 if !(ufs.IsFile(srcfilepath) && withfilepathcmdarg) {192 srcfilepath = ""193 }194 src := &req.SrcLens.Str195 if *src == "" {196 src = &req.SrcLens.Txt197 }198 if (*src == "") && req.SrcLens.FilePath != "" && ufs.IsFile(req.SrcLens.FilePath) && !withfilepathcmdarg {199 req.SrcLens.EnsureSrcFull()200 src = &req.SrcLens.Txt201 }202 if *src != "" {203 srcfilepath = ""204 } else if srcfilepath == "" {205 resp.ErrMsg = "Nothing to format?!"206 return207 }208 cmdname := formatter.Name209 if Prog.Cfg.FormatterProg != "" {210 cmdname = Prog.Cfg.FormatterProg211 }212 if srcformatted, stderr := me.Impl.RunFormatter(formatter, cmdname, prefs, srcfilepath, *src); srcformatted != "" {213 *src, resp.SrcMods = srcformatted, SrcLenses{req.SrcLens}214 } else if stderr != "" {215 resp.ErrMsg = stderr216 }217}218func (me *SrcModBase) onSetDefMenu(req *IpcReq, resp *IpcResp) {219 m := Menu{Desc: "First pick a known formatter, then optionally specify a custom tool name:"}220 for _, kf := range me.Impl.KnownFormatters() {221 var cmd = MenuItem{Title: kf.Name, IpcID: IPCID_SRCMOD_FMT_SETDEFPICK}222 cmd.IpcArgs = map[string]interface{}{"fn": kf.Name, "fp": MenuItemArgPrompt{Placeholder: kf.Name,223 Prompt: Strf("Optionally enter the name of an alternative '%s'-compatible equivalent tool to use", kf.Name)}}224 cmd.Desc = Strf("➜ Pick to use '%s' (or compatible equivalent) as the default %s formatter", kf.Name, Lang.Title)225 if kf.Name != Prog.Cfg.FormatterName || !me.isFormatterCustom() {226 if cmd.Hint = "· Installed "; !kf.Installed {227 cmd.Hint = "· Not Installed "228 }229 }230 if kf.Name == Prog.Cfg.FormatterName {231 if cmd.Hint += "· Current Default "; me.isFormatterCustom() {232 cmd.Hint += "— Using '" + Prog.Cfg.FormatterProg + "' "233 }234 }235 cmd.Hint += "· " + kf.Website236 m.Items = append(m.Items, &cmd)237 }238 resp.Menu = &MenuResponse{SubMenu: &m}239}240func (me *SrcModBase) onSetDefPick(req *IpcReq, resp *IpcResp) {241 m := req.IpcArgs.(map[string]interface{})242 Prog.Cfg.FormatterName = m["fn"].(string)243 if Prog.Cfg.FormatterProg = m["fp"].(string); Prog.Cfg.FormatterProg == Prog.Cfg.FormatterName {244 Prog.Cfg.FormatterProg = ""245 }246 if err := Prog.Cfg.Save(); err != nil {247 resp.ErrMsg = err.Error()248 } else {249 resp.Menu = &MenuResponse{}250 resp.Menu.NoteInfo = Strf("Default %s formatter changed to '%s'", Lang.Title, Prog.Cfg.FormatterName)251 if me.isFormatterCustom() {252 resp.Menu.NoteInfo += Strf("-compatible equivalent '%s'", Prog.Cfg.FormatterProg)253 }254 resp.Menu.NoteInfo += "."255 }256}...

Full Screen

Full Screen

codeAction_test.go

Source:codeAction_test.go Github

copy

Full Screen

...53 Title: generateConceptTitle,54 Arguments: []interface{}{concpetInfo{ConceptName: "# foo bar\n* "}},55 },56 }57 got, err := codeActions(&jsonrpc2.Request{Params: &p})58 if err != nil {59 t.Errorf("expected error to be nil. \nGot : %s", err)60 }61 if !reflect.DeepEqual(got, want) {62 t.Errorf("want: `%s`,\n got: `%s`", want, got)63 }64}65func TestGetCodeActionForUnimplementedStepWithParam(t *testing.T) {66 openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}67 openFilesCache.add(lsp.DocumentURI("foo.spec"), "# spec heading\n## scenario heading\n* foo bar \"some\"")68 stub := "a stub for unimplemented step"69 d := []lsp.Diagnostic{70 {71 Range: lsp.Range{72 Start: lsp.Position{Line: 2, Character: 0},73 End: lsp.Position{Line: 2, Character: 9},74 },75 Message: "Step implantation not found",76 Severity: 1,77 Code: stub,78 },79 }80 codeActionParams := lsp.CodeActionParams{81 TextDocument: lsp.TextDocumentIdentifier{URI: "foo.spec"},82 Context: lsp.CodeActionContext{Diagnostics: d},83 Range: lsp.Range{84 Start: lsp.Position{Line: 2, Character: 0},85 End: lsp.Position{Line: 2, Character: 9},86 },87 }88 b, _ := json.Marshal(codeActionParams)89 p := json.RawMessage(b)90 want := []lsp.Command{91 {92 Command: generateStepCommand,93 Title: generateStubTitle,94 Arguments: []interface{}{stub},95 },96 {97 Command: generateConceptCommand,98 Title: generateConceptTitle,99 Arguments: []interface{}{concpetInfo{ConceptName: "# foo bar <arg0>\n* "}},100 },101 }102 got, err := codeActions(&jsonrpc2.Request{Params: &p})103 if err != nil {104 t.Errorf("expected error to be nil. \nGot : %s", err)105 }106 if !reflect.DeepEqual(got, want) {107 t.Errorf("want: `%s`,\n got: `%s`", want, got)108 }109}110func TestGetCodeActionForUnimplementedStepWithTableParam(t *testing.T) {111 specText := `#Specification Heading112##Scenario Heading113* Step text114 |Head|115 |----|116 |some|`117 openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}118 openFilesCache.add(lsp.DocumentURI("foo.spec"), specText)119 stub := "a stub for unimplemented step"120 d := []lsp.Diagnostic{121 {122 Range: lsp.Range{123 Start: lsp.Position{Line: 4, Character: 0},124 End: lsp.Position{Line: 4, Character: 12},125 },126 Message: "Step implantation not found",127 Severity: 1,128 Code: stub,129 },130 }131 codeActionParams := lsp.CodeActionParams{132 TextDocument: lsp.TextDocumentIdentifier{URI: "foo.spec"},133 Context: lsp.CodeActionContext{Diagnostics: d},134 Range: lsp.Range{135 Start: lsp.Position{Line: 4, Character: 0},136 End: lsp.Position{Line: 4, Character: 12},137 },138 }139 b, _ := json.Marshal(codeActionParams)140 p := json.RawMessage(b)141 want := []lsp.Command{142 {143 Command: generateStepCommand,144 Title: generateStubTitle,145 Arguments: []interface{}{stub},146 },147 {148 Command: generateConceptCommand,149 Title: generateConceptTitle,150 Arguments: []interface{}{concpetInfo{ConceptName: "# Step text <arg0>\n* "}},151 },152 }153 got, err := codeActions(&jsonrpc2.Request{Params: &p})154 if err != nil {155 t.Errorf("expected error to be nil. \nGot : %s", err)156 }157 if !reflect.DeepEqual(got, want) {158 t.Errorf("want: `%s`,\n got: `%s`", want, got)159 }160}161func TestGetCodeActionForUnimplementedStepWithFileParameter(t *testing.T) {162 specText := `#Specification Heading163##Scenario Heading164* Step text <file:_testdata/dummyFile.txt>`165 openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}166 openFilesCache.add(lsp.DocumentURI("foo.spec"), specText)167 stub := "a stub for unimplemented step"168 d := []lsp.Diagnostic{169 {170 Range: lsp.Range{171 Start: lsp.Position{Line: 4, Character: 0},172 End: lsp.Position{Line: 4, Character: 12},173 },174 Message: "Step implantation not found",175 Severity: 1,176 Code: stub,177 },178 }179 codeActionParams := lsp.CodeActionParams{180 TextDocument: lsp.TextDocumentIdentifier{URI: "foo.spec"},181 Context: lsp.CodeActionContext{Diagnostics: d},182 Range: lsp.Range{183 Start: lsp.Position{Line: 4, Character: 0},184 End: lsp.Position{Line: 4, Character: 12},185 },186 }187 b, _ := json.Marshal(codeActionParams)188 p := json.RawMessage(b)189 want := []lsp.Command{190 {191 Command: generateStepCommand,192 Title: generateStubTitle,193 Arguments: []interface{}{stub},194 },195 {196 Command: generateConceptCommand,197 Title: generateConceptTitle,198 Arguments: []interface{}{concpetInfo{ConceptName: "# Step text <arg0>\n* "}},199 },200 }201 got, err := codeActions(&jsonrpc2.Request{Params: &p})202 if err != nil {203 t.Errorf("expected error to be nil. \nGot : %s", err)204 }205 if !reflect.DeepEqual(got, want) {206 t.Errorf("want: `%s`,\n got: `%s`", want, got)207 }208}...

Full Screen

Full Screen

codeActions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conn := jsonrpc2util.NewBufferedStream(jsonrpc2.NewConn(context.Background(), jsonrpc2.NewHeaderStream(os.Stdin, os.Stdout), handler2.NewHandler(func(ctx context.Context, req *jsonrpc2.Request) (result interface{}, err error) {4 })))5 defer conn.Close()6 ctx := context.Background()7 client := lsp.NewClientDispatcher(conn)8 server := lsp.NewServerDispatcher(conn)9 if err := server.Initialize(ctx, &protocol.InitializeParams{10 ProcessID: os.Getpid(),11 RootURI: protocol.URIFromPath(os.Args[1]),12 Capabilities: protocol.ClientCapabilities{13 TextDocument: &protocol.TextDocumentClientCapabilities{14 CodeAction: &protocol.CodeActionCapabilities{15 CodeActionLiteralSupport: &protocol.CodeActionLiteralSupport{16 CodeActionKind: &protocol.CodeActionKind{17 ValueSet: []protocol.CodeActionKind{18 },19 },20 },21 },22 },23 },24 }); err != nil {25 log.Fatal(err)26 }27 if err := server.Initialized(ctx, &protocol.InitializedParams{}); err != nil {28 log.Fatal(err)29 }30 if err := client.RegisterCapability(ctx, &protocol.RegistrationParams{31 Registrations: []protocol.Registration{32 {33 RegisterOptions: protocol.DidChangeWatchedFilesRegistrationOptions{34 Watchers: []protocol.FileSystemWatcher{35 {36 },

Full Screen

Full Screen

codeActions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := context.Background()4 conn := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(jsonrpc2.NewHeaderStream(os.Stdin, os.Stdout), jsonrpc2.VSCodeObjectCodec{}), nil)5 resp, err := conn.Call(ctx, req)6 if err != nil {7 log.Fatal(err)8 }9 fmt.Println(resp)10}11import (12func main() {13 ctx := context.Background()14 conn := jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(jsonrpc2.NewHeaderStream(os.Stdin, os.Stdout), jsonrpc2.VSCodeObjectCodec{}), nil)

Full Screen

Full Screen

codeActions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := exec.Command("bash")4 f, err := pty.Start(cmd)5 if err != nil {6 log.Fatal(err)7 }8 defer f.Close()9 stream := jsonrpc2.NewHeaderStream(f, f)10 defer stream.Close()11 ctx := context.Background()12 client := jsonrpc2.NewConn(ctx, stream)13 var result interface{}14 err = client.Call(ctx, "initialize", map[string]interface{}{15 "capabilities": map[string]interface{}{16 "workspace": map[string]interface{}{17 },18 "textDocument": map[string]interface{}{19 "completion": map[string]interface{}{20 "completionItem": map[string]interface{}{21 },22 },23 "hover": map[string]interface{}{24 "contentFormat": []string{"markdown", "plaintext"},25 },26 "signatureHelp": map[string]interface{}{27 "signatureInformation": map[string]interface{}{28 "documentationFormat": []string{"markdown", "plaintext"},29 },30 },31 "definition": map[string]interface{}{32 },33 "references": map[string]interface{}{34 },35 "documentHighlight": map[string]interface{}{36 },37 "documentSymbol": map[string]interface{}{38 },39 "codeAction": map[string]interface{}{40 "codeActionLiteralSupport": map[string]interface{}{41 "codeActionKind": map[string]interface{}{42 "valueSet": []string{

Full Screen

Full Screen

codeActions

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 codeActions, err := langserver.CodeActions(ctx, client, snapshot, view, uri, rng, options, kind)4 if err != nil {5 }6 fmt.Println(codeActions)7}8import (9func main() {10 codeLens, err := langserver.CodeLens(ctx, client, snapshot, view, uri, options)11 if err != nil {12 }13 fmt.Println(codeLens)14}15import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful