-
Notifications
You must be signed in to change notification settings - Fork 22
Description
If a command and a job have the same name, the language server will use the parameters from the job, for the command's parameters, leading to incorrect errors.
It looks like the root cause are these chunks of code, where the parameters are looked up for a command first, then a job, so if they have the same name, it falls through and returns the parameters for the job. It looks like that code needs to have a better understanding of what type the entity actually is, rather than just looking it up by name, since the name can refer to either a command or a job.
Warning
This issue exists in at least two spots, GetDefinedParams and GetOrbDefinedParams, but I did not exhaustively check for others. I'm seeing this error specifically with commands from an orb.
circleci-yaml-language-server/pkg/parser/yamlparser.go
Lines 561 to 577 in 1818ea5
| func (doc *YamlDocument) GetDefinedParams(entityName string, cache *utils.Cache) map[string]ast.Parameter { | |
| var definedParams map[string]ast.Parameter | |
| if command, ok := doc.Commands[entityName]; ok { | |
| definedParams = command.Parameters | |
| } | |
| if job, ok := doc.Jobs[entityName]; ok { | |
| definedParams = job.Parameters | |
| } | |
| if doc.IsOrbCommand(entityName, cache) || doc.IsOrbJob(entityName, cache) { | |
| return doc.GetOrbDefinedParams(entityName, cache) | |
| } | |
| return definedParams | |
| } |
circleci-yaml-language-server/pkg/parser/yamlparser.go
Lines 579 to 600 in 1818ea5
| func (doc *YamlDocument) GetOrbDefinedParams(entityName string, cache *utils.Cache) map[string]ast.Parameter { | |
| var definedParams map[string]ast.Parameter | |
| splittedName := strings.Split(entityName, "/") | |
| orbName := splittedName[0] | |
| commandOrJob := splittedName[1] | |
| orbInfo, err := doc.GetOrFetchOrbInfo(doc.Orbs[orbName], cache) | |
| if err != nil { | |
| return definedParams | |
| } | |
| if command, ok := orbInfo.Commands[commandOrJob]; ok { | |
| definedParams = command.Parameters | |
| } | |
| if job, ok := orbInfo.Jobs[commandOrJob]; ok { | |
| definedParams = job.Parameters | |
| } | |
| return definedParams | |
| } |