-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A generic provider that can be used to create an external provider for any language that is compliant with LSP 3.17 specifications. Adds `go` provider that is initialized using the generic provider binary. --------- Signed-off-by: Chanakya Thirumala Setty <[email protected]>
- Loading branch information
1 parent
3fab15f
commit 8b9d2f6
Showing
18 changed files
with
393 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Python Provider using Generic Provider | ||
|
||
We are using the jedi-language-server (https://github.com/pappasam/jedi-language-server) to make a python provider using the generic provider. | ||
|
||
jedi-language-server can be installed using | ||
|
||
``` | ||
pip install jedi-langauge-server | ||
``` | ||
|
||
It will be installed in `/home/<user_name>/.local/bin/jedi-language-server` | ||
|
||
It will run without any arguments, but for more information it can be run with `--log-file LOG_FILE --verbose` | ||
|
||
The configuration used was: | ||
|
||
```json | ||
{ | ||
"name": "python", | ||
"binaryPath": "/path/to/generic/provider/binary", | ||
"initConfig": [{ | ||
"location": "examples/python", | ||
"analysisMode": "full", | ||
"providerSpecificConfig": { | ||
"name": "python", | ||
"lspServerPath": "/path/to/jedi/language/server", | ||
} | ||
}] | ||
}, | ||
``` | ||
|
||
The rule used to test it out was: | ||
|
||
```yaml | ||
- message: python sample rule | ||
ruleID: python-sample-rule-001 | ||
when: | ||
python.referenced: | ||
pattern: "create_custom_resource_definition" | ||
``` | ||
The example used for testing was: | ||
```python | ||
#!/usr/bin/env python | ||
|
||
import kubernetes | ||
|
||
def main(): | ||
print(kubernetes.client.ApiextensionsV1beta1Api.create_custom_resource_definition) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
``` | ||
## Findings | ||
The jedi-language-server was able to get initialized and communicate with the analyzer-lsp. | ||
However, it returned `null` as a response to the rule. | ||
|
||
After further testing, it was found that the jedi-language-server isn't able to find references to imported functions. | ||
|
||
jedi-language-server returned a response when the rule was | ||
|
||
```yaml | ||
- message: python sample rule | ||
ruleID: python-sample-rule-001 | ||
when: | ||
python.referenced: | ||
pattern: "main" | ||
``` | ||
|
||
## Results | ||
|
||
We are going to move onto a different language server to test out the Generic Provider. | ||
|
||
We are also going to investigate the behaviour of jedi-language-server to see whether not recognizing imported functions is intended. And also investigate GoPls to see whether recognizing imported functions is intended. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
external-providers/generic-external-provider/pkg/generic/dependency.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package generic | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/konveyor/analyzer-lsp/provider" | ||
"go.lsp.dev/uri" | ||
) | ||
|
||
func (g *genericServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, error) { | ||
cmdStr, isString := g.config.ProviderSpecificConfig["dependencyProviderPath"].(string) | ||
if !isString { | ||
return nil, fmt.Errorf("dependency provider path is not a string") | ||
} | ||
// Expects dependency provider to output provider.Dep structs to stdout | ||
cmd := exec.Command(cmdStr) | ||
cmd.Dir = g.config.Location | ||
dataR, err := cmd.Output() | ||
if err != nil { | ||
return nil, err | ||
} | ||
data := string(dataR) | ||
if len(data) == 0 { | ||
return nil, nil | ||
} | ||
m := map[uri.URI][]*provider.Dep{} | ||
err = json.Unmarshal([]byte(data), &m) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return m, err | ||
} | ||
|
||
func (p *genericServiceClient) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { | ||
return nil, nil | ||
} |
2 changes: 1 addition & 1 deletion
2
...al-provider/pkg/golang/dependency_test.go → ...l-provider/pkg/generic/dependency_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package golang | ||
package generic | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.