-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go fs #219
Go fs #219
Conversation
Need to update this to be in sync with updates in the imports pr |
pkg/lang/golang/arguments.go
Outdated
} | ||
|
||
func (a *Argument) IsString() bool { | ||
return a.Type == "interpreted_string_literal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intent here not to match raw_string_literal
(using backticks - ``)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah is that a valid go node type with the only difference being `` instead of ""? If so, i definitely need to add that
pkg/lang/golang/plugin_fs.go
Outdated
for _, f := range unit.Files() { | ||
goSource, ok := Language.ID.CastFile(f) | ||
if !ok { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could be simplified with
for _, goSource := range unit.FilesOfLang(goLang) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update
} | ||
|
||
args[0].Content = "nil" | ||
args[1].Content = fmt.Sprintf(`os.Getenv("%s")`, fsEnvVar.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we check to make sure os
is imported anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- good callout, i need to make a bunch of updates but i definitely missed this originally
pkg/lang/golang/plugin_fs.go
Outdated
args[0].Content = "nil" | ||
args[1].Content = fmt.Sprintf(`os.Getenv("%s")`, fsEnvVar.Name) | ||
|
||
newNodeContent := strings.Replace(result.args.Content(), result.args.Content(), ArgumentListToString(args), 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused here. Won't the outcome of strings.Replace()
always be to replace the entirety of the original string with the value of ArgumentListToString(args)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah so were replacing all of the args node which is (var1, var2) with our new args (newVar1, newVar2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What David's saying is that this is the same as
newNodeContent := ArgumentListToString(args)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah i see, good point let me update
@@ -0,0 +1,18 @@ | |||
(short_var_declaration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no long var declarations? 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess not, go is a simpleton
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably won't handle:
var bucket, err = fileblob.OpenBucket(myDir, myConnector)
(presumably the (long) var_declaration
)
or
var bucket, err
bucket, err = fileblob.OpenBucket(myDir, myConnector)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me update the query, should be able to make it work without having to change any of the logic i believe
pkg/lang/golang/runtime_test.go
Outdated
func (n NoopRuntime) GetFsImports() []string { | ||
return []string{ | ||
"gocloud.dev/blob", | ||
"_ \"gocloud.dev/blob/s3blob\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"_ \"gocloud.dev/blob/s3blob\"", | |
`_ "gocloud.dev/blob/s3blob"`, |
nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, caused updated tests to break as well so this should be fixed. Was leftover from the go imports pr that was updated
pkg/lang/golang/imports.go
Outdated
@@ -64,14 +74,23 @@ func UpdateImportsInFile(f *core.SourceFile, importsToAdd []string, importsToRem | |||
|
|||
// Determine which imports already exist and which we need to add | |||
for _, i := range importsToAdd { | |||
importChunks := strings.Split(i, "\"") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importChunks := strings.Split(i, "\"") | |
importChunks := strings.Split(i, `"`) |
nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be removed now since we take in imports
pkg/lang/golang/aws_runtime/aws.go
Outdated
func (r *AwsRuntime) GetFsImports() []string { | ||
return []string{ | ||
"gocloud.dev/blob", | ||
"_ \"gocloud.dev/blob/s3blob\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"_ \"gocloud.dev/blob/s3blob\"", | |
`_ "gocloud.dev/blob/s3blob"`, |
nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -0,0 +1,18 @@ | |||
(short_var_declaration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably won't handle:
var bucket, err = fileblob.OpenBucket(myDir, myConnector)
(presumably the (long) var_declaration
)
or
var bucket, err
bucket, err = fileblob.OpenBucket(myDir, myConnector)
@@ -0,0 +1,4 @@ | |||
; Finds arguments in an arguments_list | |||
(argument_list [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the [
for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i copied this over from python, must have just been leftover, will remove
378c393
to
91f3dd9
Compare
|
} | ||
|
||
// GetArguements is passed a tree-sitter node, which is of type argument_list, and returns a list of in order Arguments | ||
func GetArguements(args *sitter.Node) []Argument { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
- GetArguements
+ GetArguments
nextMatch := doQuery(args, findArgs) | ||
for { | ||
match, found := nextMatch() | ||
if !found { | ||
break | ||
} | ||
|
||
arg := match["arg"] | ||
if arg == nil { | ||
continue | ||
} | ||
|
||
arguments = append(arguments, Argument{Content: arg.Content(), Type: arg.Type()}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally optional, but you and also just do:
selection := query.Select(query.Exec(language, args, findArgs), query.ParamNamed("arg"))
for _, arg := range query.Collect(selection) {
arguments = append(arguments, Argument{Content: arg.Content(), Type: arg.Type()})
}
@@ -47,6 +47,16 @@ func GetImportsInFile(f *core.SourceFile) []Import { | |||
return imports | |||
} | |||
|
|||
func GetNamedImportInFile(f *core.SourceFile, namedImport string) Import { | |||
imports := GetImportsInFile(f) | |||
for _, i := range imports { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor-ish: I pretty much always assume i
is an index in a for
, so this threw me off at first. Maybe imp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah because i have changes in other prs i will go ahead and update in a future pr. Same with the above comments
• Does any part of it require special attention?
• Does it relate to or fix any issue?
This is the parsing and transformation side of https://github.com/klothoplatform/klotho-history/issues/466.
We look for the fileblob and transform that to the s3 defintition found in https://gocloud.dev/howto/blob/.
Going to do the IAC side after this so it doesnt grow too large
Standard checks