github.com/tiagovtristao/plz@v13.4.0+incompatible/tools/build_langserver/langserver/setup_test.go (about) 1 package langserver 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/thought-machine/please/src/core" 8 "io/ioutil" 9 "github.com/thought-machine/please/tools/build_langserver/lsp" 10 ) 11 12 // TODO(bnm): cleanup setup 13 // TestMain runs the setup for the tests for all the tests relating to langserver 14 func TestMain(m *testing.M) { 15 core.FindRepoRoot() 16 17 // store files in handler workspace 18 URIs := []lsp.DocumentURI{exampleBuildURI, assignBuildURI, propURI, miscURI, completionURI, completion2URI, 19 completionPropURI, completionLabelURI, completionLiteralURI, completionStmtURI, sigURI, subincludeURI, 20 reformatURI, reformat2URI} 21 for _, i := range URIs { 22 storeFile(i) 23 } 24 25 retCode := m.Run() 26 os.Exit(retCode) 27 } 28 29 var exampleBuildURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/example.build") 30 var subincludeURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/subinclude.build") 31 var assignBuildURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/assignment.build") 32 var propURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/property.build") 33 var miscURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/misc.build") 34 var completionURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/completion.build") 35 var completion2URI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/completion2.build") 36 var completionPropURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/completion_props.build") 37 var completionLabelURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/completion_buildlabels.build") 38 var completionLiteralURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/completion_literal.build") 39 var completionStmtURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/completion_stmt.build") 40 var sigURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/signature.build") 41 var OutScopeURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/out_of_scope.build") 42 var reformatURI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/reformat.build") 43 var reformat2URI = lsp.DocumentURI("file://tools/build_langserver/langserver/test_data/reformat2.build") 44 45 var analyzer, _ = newAnalyzer() 46 47 var handler = LsHandler{ 48 repoRoot: core.RepoRoot, 49 workspace: newWorkspaceStore(lsp.DocumentURI(core.RepoRoot)), 50 analyzer: analyzer, 51 init: &lsp.InitializeParams{ 52 RootURI: lsp.DocumentURI(core.RepoRoot), 53 Capabilities: lsp.ClientCapabilities{ 54 TextDocument: lsp.TextDocumentClientCapabilities{ 55 Completion: lsp.Completion{ 56 CompletionItem: struct { 57 SnippetSupport bool `json:"snippetSupport,omitempty"` 58 }{SnippetSupport: true}}, 59 }, 60 }, 61 }, 62 } 63 64 func storeFile(uri lsp.DocumentURI) error { 65 66 return storeFileWithCustomHandler(uri, &handler) 67 } 68 69 func storeFileWithCustomHandler(uri lsp.DocumentURI, h *LsHandler) error { 70 filePath, err := GetPathFromURL(uri, "file") 71 if err != nil { 72 return err 73 } 74 75 b, err := ioutil.ReadFile(filePath) 76 if err != nil { 77 return err 78 } 79 80 h.workspace.Store(uri, string(b), 1) 81 return nil 82 }