Best Gauge code snippet using lang.getDiagnostics
diagnostics.go
Source:diagnostics.go
...28 isInQueue = true29 diagnosticsLock.Lock()30 defer diagnosticsLock.Unlock()31 isInQueue = false32 diagnosticsMap, err := getDiagnostics()33 if err != nil {34 logError(nil, "Unable to publish diagnostics, error : %s", err.Error())35 return36 }37 for uri, diagnostics := range diagnosticsMap {38 err := publishDiagnostic(uri, diagnostics, conn, ctx)39 if err != nil {40 logError(nil, "Unable to publish diagnostics for %s, error : %s", uri, err.Error())41 }42 }43 }44}45func publishDiagnostic(uri lsp.DocumentURI, diagnostics []lsp.Diagnostic, conn jsonrpc2.JSONRPC2, ctx context.Context) error {46 params := lsp.PublishDiagnosticsParams{URI: uri, Diagnostics: diagnostics}47 return conn.Notify(ctx, "textDocument/publishDiagnostics", params)48}49func getDiagnostics() (map[lsp.DocumentURI][]lsp.Diagnostic, error) {50 diagnostics := make(map[lsp.DocumentURI][]lsp.Diagnostic)51 conceptDictionary, err := validateConcepts(diagnostics)52 if err != nil {53 return nil, err54 }55 if err = validateSpecs(conceptDictionary, diagnostics); err != nil {56 return nil, err57 }58 return diagnostics, nil59}60func createValidationDiagnostics(errors []error, diagnostics map[lsp.DocumentURI][]lsp.Diagnostic) {61 for _, err := range errors {62 uri := util.ConvertPathToURI(err.(validation.StepValidationError).FileName())63 s := err.(validation.StepValidationError).Step()...
diagnostics_test.go
Source:diagnostics_test.go
...65 Message: "Multiple spec headings found in same file",66 Severity: 1,67 },68 }69 diagnostics, err := getDiagnostics()70 if err != nil {71 t.Errorf("Expected no error, got : %s", err.Error())72 }73 got := diagnostics[uri]74 if !reflect.DeepEqual(got, want) {75 t.Errorf("want: `%+v`,\n got: `%+v`", want, got)76 }77}78func TestDiagnosticWithNoErrors(t *testing.T) {79 setup()80 specText := `Specification Heading81=====================82Scenario Heading83----------------84* Step text85`86 uri := util.ConvertPathToURI(specFile)87 openFilesCache.add(uri, specText)88 d, err := getDiagnostics()89 if err != nil {90 t.Errorf("expected no error.\n Got: %s", err.Error())91 }92 if len(d[uri]) > 0 {93 t.Errorf("expected no error.\n Got: %+v", d)94 }95}96func TestParseConcept(t *testing.T) {97 setup()98 cptText := `# concept99* foo100`101 uri := util.ConvertPathToURI(conceptFile)102 openFilesCache.add(uri, cptText)103 diagnostics := make(map[lsp.DocumentURI][]lsp.Diagnostic)104 dictionary, err := validateConcepts(diagnostics)105 if err != nil {106 t.Errorf("expected no error.\n Got: %s", err.Error())107 }108 if len(dictionary.ConceptsMap) == 0 {109 t.Errorf("Concept dictionary is empty")110 }111 if len(diagnostics[uri]) > 0 {112 t.Errorf("Parsing failed, got : %+v", diagnostics)113 }114}115func TestDiagnosticsForConceptParseErrors(t *testing.T) {116 setup()117 cptText := `# concept`118 uri := util.ConvertPathToURI(conceptFile)119 openFilesCache.add(uri, cptText)120 diagnostics := make(map[lsp.DocumentURI][]lsp.Diagnostic)121 _, err := validateConcepts(diagnostics)122 if err != nil {123 t.Error(err)124 }125 if len(diagnostics[uri]) <= 0 {126 t.Errorf("expected parse errors")127 }128 want := []lsp.Diagnostic{129 {130 Range: lsp.Range{131 Start: lsp.Position{Line: 0, Character: 0},132 End: lsp.Position{Line: 0, Character: 9},133 },134 Message: "Concept should have atleast one step",135 Severity: 1,136 },137 }138 if !reflect.DeepEqual(want, diagnostics[uri]) {139 t.Errorf("want: `%v`,\n got: `%v`", want, diagnostics[uri])140 }141}142func TestDiagnosticOfConceptsWithCircularReference(t *testing.T) {143 setup()144 cptText := `# concept145* concept146`147 uri := util.ConvertPathToURI(conceptFile)148 openFilesCache.add(uri, cptText)149 diagnostics, err := getDiagnostics()150 if err != nil {151 t.Errorf("expected no error.\n Got: %s", err.Error())152 }153 got := diagnostics[uri]154 containsDiagnostics(got, 1, 0, "Circular reference found in concept.", t)155}156var containsDiagnostics = func(diagnostics []lsp.Diagnostic, line1, line2 int, startMessage string, t *testing.T) {157 for _, diagnostic := range diagnostics {158 if !strings.Contains(diagnostic.Message, startMessage) {159 t.Errorf("Invalid error message, got : %s : ", diagnostic.Message)160 }161 if (diagnostic.Range.Start.Line != line1 || diagnostic.Range.Start.Line != line2) && diagnostic.Range.Start.Character != 0 {162 t.Errorf("Invalid start in range, got : %+v : ", diagnostic.Range.Start)163 }...
completions.go
Source:completions.go
1package langserver2import (3 "strconv"4 "strings"5 "github.com/dbaumgarten/yodk/pkg/lsp"6 "github.com/dbaumgarten/yodk/pkg/parser/ast"7)8func (s *LangServer) GetCompletions(params *lsp.CompletionParams) (*lsp.CompletionList, error) {9 var items []lsp.CompletionItem10 if strings.HasSuffix(string(params.TextDocument.URI), ".yolol") {11 items = make([]lsp.CompletionItem, 0, len(DefaultYololCompletions)+15)12 items = append(items, DefaultYololCompletions...)13 items = append(items, s.getVariableCompletions(params)...)14 } else if strings.HasSuffix(string(params.TextDocument.URI), ".nolol") {15 items = make([]lsp.CompletionItem, 0, len(DefaultNololCompletions)+30)16 items = append(items, DefaultNololCompletions...)17 items = append(items, s.getNololCompletions(params)...)18 } else {19 return nil, nil20 }21 return &lsp.CompletionList{22 IsIncomplete: false,23 Items: items,24 }, nil25}26func (s *LangServer) getNololCompletions(params *lsp.CompletionParams) []lsp.CompletionItem {27 diags, err := s.cache.GetDiagnostics(params.TextDocument.URI)28 if err != nil {29 return []lsp.CompletionItem{}30 }31 analysis := diags.AnalysisReport32 if analysis == nil {33 return []lsp.CompletionItem{}34 }35 items := make([]lsp.CompletionItem, len(analysis.Variables)+len(analysis.Definitions)+len(analysis.Macros))36 for _, v := range analysis.GetVarsAtLine(int(params.Position.Line) + 1) {37 items = append(items, lsp.CompletionItem{38 Label: v,39 Kind: 6,40 })41 }42 for _, m := range analysis.Macros {43 text := m.Name + "(" + strings.Join(m.Arguments, ",") + ")"44 if len(m.Externals) > 0 {45 text += "<" + strings.Join(m.Externals, ",") + ">"46 }47 text += " " + m.Type48 item := lsp.CompletionItem{49 Detail: text,50 Label: m.Name,51 Kind: 15,52 InsertText: m.Name + argsToSnippet(m.Arguments),53 InsertTextFormat: 2,54 }55 if doc, exists := analysis.Docstrings[m.Name]; exists {56 item.Documentation = doc57 }58 items = append(items, item)59 }60 for _, d := range analysis.Definitions {61 kind := 21.062 insert := ""63 detail := ""64 item := lsp.CompletionItem{65 Label: d.Name,66 Kind: kind,67 InsertText: insert,68 Detail: detail,69 InsertTextFormat: 2,70 }71 if doc, exists := analysis.Docstrings[d.Name]; exists {72 item.Documentation = doc73 }74 items = append(items, item)75 }76 for _, l := range analysis.Labels {77 items = append(items, lsp.CompletionItem{78 Label: l,79 Kind: 13,80 })81 }82 return items83}84func (s *LangServer) getVariableCompletions(params *lsp.CompletionParams) []lsp.CompletionItem {85 diags, err := s.cache.GetDiagnostics(params.TextDocument.URI)86 if err != nil {87 return []lsp.CompletionItem{}88 }89 if diags.Variables == nil {90 return []lsp.CompletionItem{}91 }92 items := make([]lsp.CompletionItem, len(diags.Variables))93 for i, v := range diags.Variables {94 item := lsp.CompletionItem{95 Label: v,96 Kind: 6,97 }98 if strings.HasPrefix(v, ":") {99 item.Kind = 5100 }101 items[i] = item102 }103 return items104}105// Find all variable-names that are used inside a program106func findUsedVariables(prog *ast.Program) []string {107 variables := make(map[string]bool)108 f := func(node ast.Node, visitType int) error {109 if assign, is := node.(*ast.Assignment); visitType == ast.PreVisit && is {110 variables[assign.Variable] = true111 }112 if deref, is := node.(*ast.Dereference); visitType == ast.SingleVisit && is {113 variables[deref.Variable] = true114 }115 return nil116 }117 prog.Accept(ast.VisitorFunc(f))118 vars := make([]string, 0, len(variables))119 for k := range variables {120 vars = append(vars, k)121 }122 return vars123}124func argsToSnippet(args []string) string {125 snip := "("126 for i, arg := range args {127 snip += "${" + strconv.Itoa(i+1) + ":" + arg + "}"128 if i != len(args)-1 {129 snip += ","130 }131 }132 snip += ")$0"133 return snip134}...
getDiagnostics
Using AI Code Generation
1import (2func main() {3 f, err := parser.ParseFile(nil, path, nil, parser.ParseComments)4 if err != nil {5 fmt.Println("Error parsing file")6 }7 conf := types.Config{Error: func(err error) {8 fmt.Println("Error in configuration")9 }}10 pkg, err := conf.Check(path, nil, []*ast.File{f}, nil)11 if err != nil {12 fmt.Println("Error in package")13 }14 diag := pkg.GetDiagnostics()15 fmt.Println("Diagnostics : ", diag)16}
getDiagnostics
Using AI Code Generation
1import (2func main() {3 if err != nil {4 log.Fatalf("Failed to connect to the Ethereum client: %v", err)5 }6 auth, err := bind.NewTransactor(strings.NewReader(key), "password")7 if err != nil {8 log.Fatalf("Failed to create authorized transactor: %v", err)9 }10 address, tx, instance, err := DeployAwesome(auth, client)11 if err != nil {12 log.Fatalf("Failed to deploy new contract: %v", err)13 }14 fmt.Println(address.Hex())15 fmt.Println(tx.Hash().Hex())
getDiagnostics
Using AI Code Generation
1import (2func main() {3 conn := jsonrpc2.NewConn(context.Background(), jsonrpc2.NewBufferedStream(os.Stdin, jsonrpc2.VSCodeObjectCodec{}), lsp.NewHandler(&lang{}))4 err := conn.Call(context.Background(), "initialize", lsp.InitializeParams{5 }, &result)6 if err != nil {7 log.Fatal(err)8 }9 err = conn.Notify(context.Background(), "initialized", lsp.InitializedParams{})10 if err != nil {11 log.Fatal(err)12 }13 err = conn.Notify(context.Background(), "textDocument/didOpen", lsp.DidOpenTextDocumentParams{14 TextDocument: lsp.TextDocumentItem{15 Text: string(data),16 },17 })18 if err != nil {19 log.Fatal(err)20 }21 err = conn.Notify(context.Background(), "textDocument/didChange", lsp.DidChangeTextDocumentParams{22 TextDocument: lsp.VersionedTextDocumentIdentifier{23 TextDocumentIdentifier: lsp.TextDocumentIdentifier{24 },25 },26 ContentChanges: []lsp.TextDocumentContentChangeEvent{27 {28 Text: string(data),29 },30 },31 })32 if err != nil {33 log.Fatal(err)34 }
getDiagnostics
Using AI Code Generation
1import (2func main() {3 vm := otto.New()4 lang, _ := vm.Object(`lang = {}`)5 lang.Set("getDiagnostics", func(call otto.FunctionCall) otto.Value {6 fmt.Println("getDiagnostics called")7 return otto.Value{}8 })9 vm.Set("lang", lang)10 vm.Run(`11 lang.getDiagnostics();12}13import (14type Lang struct {15}16func (lang *Lang) getDiagnostics() {17 fmt.Println("getDiagnostics called")18}19type LangInterface interface {20 getDiagnostics()21}22func main() {23 lang := &Lang{}24 useDiagnostics(lang)25}26func useDiagnostics(lang LangInterface) {27 lang.getDiagnostics()28}
getDiagnostics
Using AI Code Generation
1import (2type server struct{}3func (s *server) Initialize(ctx context.Context, params *lsp.InitializeParams) (*lsp.InitializeResult, error) {4 return &lsp.InitializeResult{5 Capabilities: lsp.ServerCapabilities{6 CompletionProvider: &lsp.CompletionOptions{7 TriggerCharacters: []string{"."},8 },9 },10 }, nil11}12func (s *server) Initialized(ctx context.Context, params *lsp.InitializedParams) error {13}14func (s *server) Shutdown(ctx context.Context) error {15}16func (s *server) Exit(ctx context.Context) error {17}18func (s *server) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocumentParams) error {19}20func (s *server) DidChange(ctx context.Context, params *lsp.DidChangeTextDocumentParams) error {21}22func (s *server) DidClose(ctx context.Context, params *lsp.DidCloseTextDocumentParams) error {23}24func (s *server) DidSave(ctx context.Context, params *lsp.DidSaveTextDocumentParams) error {25}26func (s *server) Completion(ctx context.Context, params *lsp.CompletionParams) (*lsp.CompletionList, error) {27}28func (s *server) Hover(ctx context.Context, params *lsp.TextDocumentPositionParams) (*lsp.Hover, error) {29}30func (s *server) SignatureHelp(ctx context.Context, params *lsp.TextDocumentPositionParams) (*lsp.SignatureHelp, error) {31}32func (s *server) Definition(ctx context.Context, params *lsp.TextDocumentPositionParams) ([]lsp.Location, error) {33}34func (s *server) References(ctx context.Context, params *lsp.ReferenceParams) ([]lsp.Location, error) {35}36func (s *server) DocumentHighlight(ctx context.Context, params *l
getDiagnostics
Using AI Code Generation
1import (2func main() {3 vm := otto.New()4 vm.Set("answer", 42)5 vm.Run(`6 if (answer == 42) {7 console.log("The answer is 42.");8 }9 value, _ := vm.Get("answer")10 fmt.Println(value)11 fn, _ := vm.Get("console.log")12 fn.Call(fn, "Hello, World!")13 fn, _ = vm.Get("console.log")14 fn.Call(fn, "Hello, World!")15 fn, _ = vm.Get("console.log")16 fn.Call(fn, "Hello, World!")17 fn, _ = vm.Get("console.log")18 fn.Call(fn, "Hello, World!")19 fn, _ = vm.Get("console.log")20 fn.Call(fn, "Hello, World!")21 fn, _ = vm.Get("console.log")22 fn.Call(fn, "Hello, World!")23 fn, _ = vm.Get("console.log")24 fn.Call(fn, "Hello, World!")25 fn, _ = vm.Get("console.log")26 fn.Call(fn, "Hello, World!")27 fn, _ = vm.Get("console.log")28 fn.Call(fn, "Hello, World!")29 fn, _ = vm.Get("console.log")30 fn.Call(fn, "Hello, World!")31 fn, _ = vm.Get("console.log")32 fn.Call(fn, "Hello, World!")33 fn, _ = vm.Get("console.log")
getDiagnostics
Using AI Code Generation
1import (2func main() {3 absPath, _ := filepath.Abs(filePath)4 tdi := &protocol.TextDocumentItem{5 URI: protocol.NewURI(absPath),6 }7 tdi2 := &protocol.TextDocumentIdentifier{8 URI: protocol.NewURI(absPath),9 }10 tdpp := &protocol.TextDocumentPositionParams{11 Position: protocol.Position{},12 }13 tdc := &protocol.TextDocumentContentChangeEvent{14 }15 diagnostics, _ := lsp.GetDiagnostics(tdi, []protocol.TextDocumentContentChangeEvent{*tdc}, tdpp)16 fmt.Println(diagnostics)17}18import (19func main() {20 tdi := &protocol.TextDocumentItem{21 URI: protocol.NewURI(filePath),22 }23 tdi2 := &protocol.TextDocumentIdentifier{24 URI: protocol.NewURI(filePath),25 }
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!