Skip to content

Commit

Permalink
Run gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
AubreySLavigne committed Feb 28, 2020
1 parent 3626372 commit 5111a91
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 95 deletions.
8 changes: 4 additions & 4 deletions langserver/did_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func TextDocumentDidChange(ctx context.Context, vs lsp.DidChangeTextDocumentPara

DiagsFiles[fileURL] = tfstructs.GetDiagnostics(tempFile.Name(), fileURL)

TextDocumentPublishDiagnostics(ctx, lsp.PublishDiagnosticsParams{
URI: vs.TextDocument.URI,
Diagnostics: DiagsFiles[fileURL],
})
TextDocumentPublishDiagnostics(ctx, lsp.PublishDiagnosticsParams{
URI: vs.TextDocument.URI,
Diagnostics: DiagsFiles[fileURL],
})
return nil
}
8 changes: 4 additions & 4 deletions langserver/did_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func TextDocumentDidOpen(ctx context.Context, vs lsp.DidOpenTextDocumentParams)

DiagsFiles[fileURL] = tfstructs.GetDiagnostics(fileURL, fileURL)

TextDocumentPublishDiagnostics(ctx, lsp.PublishDiagnosticsParams{
URI: vs.TextDocument.URI,
Diagnostics: DiagsFiles[fileURL],
})
TextDocumentPublishDiagnostics(ctx, lsp.PublishDiagnosticsParams{
URI: vs.TextDocument.URI,
Diagnostics: DiagsFiles[fileURL],
})
tempFile.Write([]byte(vs.TextDocument.Text))
return nil
}
4 changes: 2 additions & 2 deletions langserver/initialized.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
)

type InitializedParams struct {}
type InitializedParams struct{}

func Initialized(ctx context.Context, vs InitializedParams) error {
return nil
return nil
}
18 changes: 9 additions & 9 deletions langserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ package langserver

import (
"context"
"fmt"
"fmt"
"github.com/creachadair/jrpc2"
"github.com/creachadair/jrpc2/channel"
"github.com/creachadair/jrpc2/handler"
"github.com/creachadair/jrpc2/server"
log "github.com/sirupsen/logrus"
oldLog "log"
oldLog "log"
"net"
"os"
)

func RunStdioServer(oldLogInstance *oldLog.Logger) {
isTCP = false
isTCP = false

StdioServer = jrpc2.NewServer(ServiceMap, &jrpc2.ServerOptions{
AllowPush: true,
Logger: oldLogInstance,
Logger: oldLogInstance,
})

StdioServer.Start(channel.Header("")(os.Stdin, os.Stdout))
Expand All @@ -34,7 +34,7 @@ func RunStdioServer(oldLogInstance *oldLog.Logger) {
}

func RunTCPServer(address string, port int, oldLogInstance *oldLog.Logger) {
isTCP = true
isTCP = true

lst, err := net.Listen("tcp", fmt.Sprintf("%s:%d", address, port))
if err != nil {
Expand All @@ -51,9 +51,9 @@ func RunTCPServer(address string, port int, oldLogInstance *oldLog.Logger) {
if err := server.Loop(lst, ServiceMap, &server.LoopOptions{
Framing: newChan,
ServerOptions: &jrpc2.ServerOptions{
AllowPush: true,
Logger: oldLogInstance,
},
AllowPush: true,
Logger: oldLogInstance,
},
}); err != nil {
log.Errorf("Loop: unexpected failure: %v", err)
cancelFunc()
Expand All @@ -76,7 +76,7 @@ func RunTCPServer(address string, port int, oldLogInstance *oldLog.Logger) {
func InitializeServiceMap() {
ServiceMap = handler.Map{
"initialize": handler.New(Initialize),
"initialized": handler.New(Initialized),
"initialized": handler.New(Initialized),
"textDocument/completion": handler.New(TextDocumentComplete),
"textDocument/didChange": handler.New(TextDocumentDidChange),
"textDocument/didOpen": handler.New(TextDocumentDidOpen),
Expand Down
12 changes: 6 additions & 6 deletions langserver/publish_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

func TextDocumentPublishDiagnostics(ctx context.Context, vs lsp.PublishDiagnosticsParams) error {

var resultedError error
var resultedError error

if isTCP {
resultedError = jrpc2.ServerPush(ctx, "textDocument/publishDiagnostics", vs)
} else {
resultedError = StdioServer.Push(ctx, "textDocument/publishDiagnostics", vs)
}
if isTCP {
resultedError = jrpc2.ServerPush(ctx, "textDocument/publishDiagnostics", vs)
} else {
resultedError = StdioServer.Push(ctx, "textDocument/publishDiagnostics", vs)
}

return resultedError
}
34 changes: 17 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ func main() {
log.SetOutput(f)
}

var oldLogInstance *oldLog.Logger

if *debugJRPC2 {
if !*tcp && !*enableLogFileJRPC2 {
log.Fatal("Debug for JRPC2 has to be set for log file location if is set to use stdio")
}

oldLogInstance = oldLog.New(os.Stdout, "", 0)
if *enableLogFileJRPC2 {
f, err := os.OpenFile(fmt.Sprintf("%stf-lsp-jrpc2.log", *locationJRPC2), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
oldLogInstance.SetOutput(f)
}
var oldLogInstance *oldLog.Logger

if *debugJRPC2 {
if !*tcp && !*enableLogFileJRPC2 {
log.Fatal("Debug for JRPC2 has to be set for log file location if is set to use stdio")
}

oldLogInstance = oldLog.New(os.Stdout, "", 0)
if *enableLogFileJRPC2 {
f, err := os.OpenFile(fmt.Sprintf("%stf-lsp-jrpc2.log", *locationJRPC2), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
oldLogInstance.SetOutput(f)
}
}

langserver.InitializeServiceMap()
langserver.InitializeServiceMap()

if *tcp {
langserver.RunTCPServer(*address, *port, oldLogInstance)
Expand Down
14 changes: 7 additions & 7 deletions tfstructs/diags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package tfstructs

import (
"fmt"
"os"
v2 "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/terraform/configs"
"github.com/zclconf/go-cty/cty"
"os"
//"github.com/juliosueiras/terraform-lsp/helper"
terragruntConfig "github.com/gruntwork-io/terragrunt/config"
terragruntOptions "github.com/gruntwork-io/terragrunt/options"
Expand Down Expand Up @@ -120,13 +120,13 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
resourceTypes[v.Type][v.Name] = cty.DynamicVal
}

targetDir := filepath.Dir(originalFileName)
targetDir := filepath.Dir(originalFileName)

resultedDir := ""
resultedDir := ""
searchLevel := 4
for dir := targetDir; dir != "" && searchLevel != 0; dir = filepath.Dir(dir) {
if _, err := os.Stat(filepath.Join(dir, ".terraform")); err == nil {
resultedDir = dir
resultedDir = dir
break
}
searchLevel -= 1
Expand All @@ -136,7 +136,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
"path": cty.ObjectVal(map[string]cty.Value{
"cwd": cty.StringVal(filepath.Dir(originalFileName)),
"module": cty.StringVal(filepath.Dir(originalFileName)),
"root": cty.StringVal(resultedDir),
"root": cty.StringVal(resultedDir),
}),
"var": cty.DynamicVal, // Need to check for undefined vars
"module": cty.DynamicVal,
Expand Down Expand Up @@ -198,7 +198,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
})
}

for _, local := range cfg.Locals {
for _, local := range cfg.Locals {
diags := GetLocalsForDiags(*local, filepath.Dir(originalFileName), variables)

if diags != nil {
Expand All @@ -220,7 +220,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
})
}
}
}
}

// cfg, diags := configload.NewLoader(&configload.Config{
// ModulesDir: ".terraform/modules",
Expand Down
16 changes: 8 additions & 8 deletions tfstructs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func GetModuleVariables(moduleAddr string, config hcl.Body, targetDir string) (m
func GetLocalsForDiags(local configs.Local, targetDir string, variables map[string]cty.Value) hcl.Diagnostics {
scope := lang.Scope{}

//_, diags := scope.EvalExpr(local, cty.DynamicPseudoType)
_, diags := local.Expr.Value(
&hcl.EvalContext{
// Build Full Tree
Variables: variables,
Functions: scope.Functions(),
},
)
//_, diags := scope.EvalExpr(local, cty.DynamicPseudoType)
_, diags := local.Expr.Value(
&hcl.EvalContext{
// Build Full Tree
Variables: variables,
Functions: scope.Functions(),
},
)
//res, _, diags := hcldec.PartialDecode(config, nil, &hcl.EvalContext{
// // Build Full Tree
// Variables: variables,
Expand Down
74 changes: 36 additions & 38 deletions tfstructs/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/lang"
"github.com/juliosueiras/terraform-lsp/hclstructs"
"github.com/zclconf/go-cty/cty"
"github.com/juliosueiras/terraform-lsp/helper"
"github.com/hashicorp/terraform/lang"
"github.com/sourcegraph/go-lsp"
"github.com/zclconf/go-cty/cty"
"os"
"path/filepath"
"reflect"
"path/filepath"
"os"
)

type GetVarAttributeRequest struct {
Expand All @@ -27,36 +27,35 @@ type GetVarAttributeRequest struct {
func GetVarAttributeCompletion(request GetVarAttributeRequest) []lsp.CompletionItem {
scope := lang.Scope{}

targetDir := request.FileDir
targetDir := request.FileDir

resultedDir := ""
resultedDir := ""
searchLevel := 4
for dir := targetDir; dir != "" && searchLevel != 0; dir = filepath.Dir(dir) {
if _, err := os.Stat(filepath.Join(dir, ".terraform")); err == nil {
resultedDir = dir
resultedDir = dir
break
}
searchLevel -= 1
}

helper.DumpLog(targetDir)

variables := map[string]cty.Value{
"path": cty.ObjectVal(map[string]cty.Value{
"cwd": cty.StringVal(request.FileDir),
"module": cty.StringVal(request.FileDir),
"root": cty.StringVal(resultedDir),
}),
"var": cty.DynamicVal, // Need to check for undefined vars
"module": cty.DynamicVal,
"local": cty.DynamicVal,
"each": cty.DynamicVal,
"count": cty.DynamicVal,
"terraform": cty.ObjectVal(map[string]cty.Value{
"workspace": cty.StringVal(""),
}),
}

helper.DumpLog(targetDir)

variables := map[string]cty.Value{
"path": cty.ObjectVal(map[string]cty.Value{
"cwd": cty.StringVal(request.FileDir),
"module": cty.StringVal(request.FileDir),
"root": cty.StringVal(resultedDir),
}),
"var": cty.DynamicVal, // Need to check for undefined vars
"module": cty.DynamicVal,
"local": cty.DynamicVal,
"each": cty.DynamicVal,
"count": cty.DynamicVal,
"terraform": cty.ObjectVal(map[string]cty.Value{
"workspace": cty.StringVal(""),
}),
}

if request.Variables.RootName() == "var" {
vars := request.Variables
Expand All @@ -72,18 +71,17 @@ func GetVarAttributeCompletion(request GetVarAttributeRequest) []lsp.CompletionI
}
}

testVal, _ := found.Expr.Value(
&hcl.EvalContext{
// Build Full Tree
Variables: variables,
Functions: scope.Functions(),
},
)

testVal, _ := found.Expr.Value(
&hcl.EvalContext{
// Build Full Tree
Variables: variables,
Functions: scope.Functions(),
},
)

helper.DumpLog(testVal)
helper.DumpLog(testVal)

origType := reflect.TypeOf(found.Expr)
origType := reflect.TypeOf(found.Expr)

if origType == hclstructs.ObjectConsExpr() {
items := found.Expr.(*hclsyntax.ObjectConsExpr).Items
Expand All @@ -109,9 +107,9 @@ func GetVarAttributeCompletion(request GetVarAttributeRequest) []lsp.CompletionI
}
}

helper.DumpLog(request.Variables[2:])
helper.DumpLog(testVal.Type())
request.Result = append(request.Result, helper.ParseOtherAttr(request.Variables[2:], testVal.Type(), request.Result)...)
helper.DumpLog(request.Variables[2:])
helper.DumpLog(testVal.Type())
request.Result = append(request.Result, helper.ParseOtherAttr(request.Variables[2:], testVal.Type(), request.Result)...)

return request.Result

Expand Down

0 comments on commit 5111a91

Please sign in to comment.