diff --git a/demo-output.yaml b/demo-output.yaml index ac9e0884..05bfa1b3 100644 --- a/demo-output.yaml +++ b/demo-output.yaml @@ -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: @@ -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 @@ -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: @@ -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: @@ -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: diff --git a/lsp/base_service_client/base_capabilities.go b/lsp/base_service_client/base_capabilities.go index 01b0eaab..af45673f 100644 --- a/lsp/base_service_client/base_capabilities.go +++ b/lsp/base_service_client/base_capabilities.go @@ -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)