Skip to content

Commit

Permalink
Fixed windows path issue again
Browse files Browse the repository at this point in the history
  • Loading branch information
juliosueiras committed Feb 20, 2020
1 parent f01c300 commit 75b31ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tfstructs/diags.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
resourceTypes[v.Type][v.Name] = cty.DynamicVal
}

if strings.Contains(originalFileNameDecoded, "\\") {
s, i := utf8.DecodeRuneInString("\\")
if []rune(originalFileNameDecoded)[0] == s {
// https://stackoverflow.com/questions/48798588/how-do-you-remove-the-first-character-of-a-string
originalFileNameDecoded = originalFileNameDecoded[i:]
}
}

targetDir := filepath.Dir(originalFileNameDecoded)
resultedDir := ""
searchLevel := 4
Expand Down Expand Up @@ -211,7 +219,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
}

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

if diags != nil {
for _, diag := range diags {
Expand Down Expand Up @@ -261,7 +269,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
for _, v := range cfg.ProviderConfigs {
providerType := v.Name

tfSchema := GetProviderSchemaForDiags(providerType, v.Config, filepath.Dir(originalFile), variables)
tfSchema := GetProviderSchemaForDiags(providerType, v.Config, filepath.Dir(originalFileNameDecoded), variables)

if tfSchema != nil {
for _, diag := range tfSchema.Diags {
Expand Down Expand Up @@ -308,7 +316,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
providerType = v.ProviderConfigRef.Name
}

tfSchema := GetResourceSchemaForDiags(resourceType, v.Config, filepath.Dir(originalFile), providerType, variables)
tfSchema := GetResourceSchemaForDiags(resourceType, v.Config, filepath.Dir(originalFileNameDecoded), providerType, variables)

if tfSchema != nil {
for _, diag := range tfSchema.Diags {
Expand Down Expand Up @@ -354,7 +362,7 @@ func GetDiagnostics(fileName string, originalFile string) []lsp.Diagnostic {
providerType = v.ProviderConfigRef.Name
}

tfSchema := GetDataSourceSchemaForDiags(resourceType, v.Config, filepath.Dir(originalFile), providerType, variables)
tfSchema := GetDataSourceSchemaForDiags(resourceType, v.Config, filepath.Dir(originalFileNameDecoded), providerType, variables)

if tfSchema != nil {
for _, diag := range tfSchema.Diags {
Expand Down
10 changes: 10 additions & 0 deletions tfstructs/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tfstructs

import (
"fmt"
"unicode/utf8"
log "github.com/sirupsen/logrus"
"go/build"
"io/ioutil"
Expand Down Expand Up @@ -187,6 +188,15 @@ func pluginDirs(targetDir string) ([]string, error) {
autoInstalledDir := ""

searchLevel := 4

if strings.Contains(targetDir, "\\") {
s, i := utf8.DecodeRuneInString("\\")
if []rune(targetDir)[0] == s {
// https://stackoverflow.com/questions/48798588/how-do-you-remove-the-first-character-of-a-string
targetDir = targetDir[i:]
}
}

for dir := targetDir; dir != "" && searchLevel != 0; dir = filepath.Dir(dir) {

log.Debug("[DEBUG] search .terraform dir in %s", dir)
Expand Down

0 comments on commit 75b31ea

Please sign in to comment.