Skip to content

Commit

Permalink
🐛 return code locations in generic provider
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Mar 4, 2024
1 parent dc1b223 commit 601d31f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
17 changes: 11 additions & 6 deletions demo-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@
category: potential
incidents:
- uri: file:///analyzer-lsp/examples/golang/main.go
message: golang apiextensions/v1/customresourcedefinitions found file:///analyzer-lsp/examples/golang/main.go:10
lineNumber: 10
message: golang apiextensions/v1/customresourcedefinitions found file:///analyzer-lsp/examples/golang/main.go:11
codeSnip: " 2 \n 3 import (\n 4 \t\"fmt\"\n 5 \n 6 \t\"github.com/konveyor/analyzer-lsp/examples/golang/dummy\"\n 7 \t\"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1\"\n 8 )\n 9 \n10 func main() {\n11 \tfmt.Println(v1beta1.CustomResourceDefinition{})\n12 \n13 \tfmt.Println(dummy.HelloWorld())\n14 }\n"
lineNumber: 11
variables:
file: file:///analyzer-lsp/examples/golang/main.go
golang-gomod-dependencies:
Expand Down Expand Up @@ -363,7 +364,8 @@
incidents:
- uri: file:///analyzer-lsp/examples/golang/main.go
message: apiextensions/v1beta1/customresourcedefinitions is deprecated, apiextensions/v1/customresourcedefinitions should be used instead
lineNumber: 10
codeSnip: " 2 \n 3 import (\n 4 \t\"fmt\"\n 5 \n 6 \t\"github.com/konveyor/analyzer-lsp/examples/golang/dummy\"\n 7 \t\"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1\"\n 8 )\n 9 \n10 func main() {\n11 \tfmt.Println(v1beta1.CustomResourceDefinition{})\n12 \n13 \tfmt.Println(dummy.HelloWorld())\n14 }\n"
lineNumber: 11
variables:
file: file:///analyzer-lsp/examples/golang/main.go
- uri: file:///analyzer-lsp/examples/java/example/src/main/java/com/example/apps/App.java
Expand Down Expand Up @@ -435,7 +437,8 @@
incidents:
- uri: file:///analyzer-lsp/examples/python/file_a.py
message: python sample rule 001
lineNumber: 2
codeSnip: " 1 import file_b\n 2 \n 3 print(file_b.hello_world())\n 4 \n 5 doggie = file_b.Dog()\n 6 print(doggie.speak())\n 7 \n 8 file_b.bad_method()\n"
lineNumber: 3
variables:
file: file:///analyzer-lsp/examples/python/file_a.py
python-sample-rule-002:
Expand All @@ -444,7 +447,8 @@
incidents:
- uri: file:///analyzer-lsp/examples/python/file_a.py
message: python sample rule 002
lineNumber: 5
codeSnip: " 1 import file_b\n 2 \n 3 print(file_b.hello_world())\n 4 \n 5 doggie = file_b.Dog()\n 6 print(doggie.speak())\n 7 \n 8 file_b.bad_method()\n"
lineNumber: 6
variables:
file: file:///analyzer-lsp/examples/python/file_a.py
python-sample-rule-003:
Expand All @@ -453,7 +457,8 @@
incidents:
- uri: file:///analyzer-lsp/examples/python/main.py
message: python sample rule 003
lineNumber: 27
codeSnip: "19 # Create an instance of the API class\n20 api_instance = kubernetes.client.ApiextensionsV1Api(api_client)\n21 body = kubernetes.client.V1CustomResourceDefinition() # V1CustomResourceDefinition | \n22 pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)\n23 dry_run = 'dry_run_example' # str | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed (optional)\n24 field_manager = 'field_manager_example' # str | fieldManager is a name associated with the actor or entity that is making these changes. The value must be less than or 128 characters long, and only contain printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. (optional)\n25 field_validation = 'field_validation_example' # str | fieldValidation instructs the server on how to handle objects in the request (POST/PUT/PATCH) containing unknown or duplicate fields. Valid values are: - Ignore: This will ignore any unknown fields that are silently dropped from the object, and will ignore all but the last duplicate field that the decoder encounters. This is the default behavior prior to v1.23. - Warn: This will send a warning via the standard warning response header for each unknown field that is dropped from the object, and for each duplicate field that is encountered. The request will still succeed if there are no other errors, and will only persist the last of any duplicate fields. This is the default in v1.23+ - Strict: This will fail the request with a BadRequest error if any unknown fields would be dropped from the object, or if any duplicate fields are present. The error returned from the server will contain all unknown and duplicate fields encountered. (optional)\n26 \n27 try:\n28 api_response = api_instance.create_custom_resource_definition(body, pretty=pretty, dry_run=dry_run, field_manager=field_manager, field_validation=field_validation)\n29 pprint(api_response)\n30 except ApiException as e:\n31 print(\"Exception when calling ApiextensionsV1Api->create_custom_resource_definition: %s\\n\" % e)\n"
lineNumber: 28
variables:
file: file:///analyzer-lsp/examples/python/main.py
singleton-sessionbean-00001:
Expand Down
13 changes: 12 additions & 1 deletion lsp/base_service_client/base_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,24 @@ func EvaluateReferenced[T base](t T, ctx ctx, cap string, info []byte) (resp, er
if err != nil {
return resp{}, err
}
lineNumber := int(ref.Range.Start.Line)
// ranges are 0 indexed
lineNumber := int(ref.Range.Start.Line) + 1
incident := provider.IncidentContext{
FileURI: u,
LineNumber: &lineNumber,
Variables: map[string]interface{}{
"file": ref.URI,
},
CodeLocation: &provider.Location{
StartPosition: provider.Position{
Line: float64(ref.Range.Start.Line) + 1,
Character: float64(ref.Range.Start.Character) + 1,
},
EndPosition: provider.Position{
Line: float64(ref.Range.End.Line) + 1,
Character: float64(ref.Range.End.Character) + 1,
},
},
}
b, _ := json.Marshal(incident)

Expand Down

0 comments on commit 601d31f

Please sign in to comment.