Language-server-protocol: Convert JSON to LSP output format ?

Created on 20 Mar 2019  路  5Comments  路  Source: microsoft/language-server-protocol

coala provides a unified interface for linting and fixing code with a single configuration file named .coafile using coala-bears. Using command-line tool, the coala output reults can be collected in a JSON file.
I was looking a way to find out how can I convert these JSON results to LSP output format? or any another way I can get LSP output over my project files whenever i run coala tool over it?
Have tried to gone through documentation but couldn't gathered much information about what I'm looking for.
Need help over this!

needs more info

Most helpful comment

@KVGarg It sounds to me like you would have to do the following based on the JSON output:

  1. Convert the line number/ranges of the warning/error/whatever in affected_code.
  2. Convert the message in message.
  3. Optionally convert severity.
  4. Use affected_code to identify the relevant Location of the file.

This is how I would start anyway. Does that help?

{
  "results": {
    "cli": [
      {
        "additional_info": "Your source code contains trailing whitespaces. Those usually have no meaning. Please consider removing them.",
        "affected_code": [
          {
            "end": {
              "column": null,
              "file": "/app/src/main.c",
              "line": 1
            },
            "file": "/app/src/main.c",
            "start": {
              "column": null,
              "file": "/app/src/main.c",
              "line": 1
            }
          }
        ],
        "aspect": "NoneType",
        "confidence": 100,
        "debug_msg": "",
        "diffs": {
          "/app/src/main.c": "--- \n+++ \n@@ -1,4 +1,4 @@\n-#include <stdio.h> \n+#include <stdio.h>\n \n int main(void) {\n     printf(\"Welcome to coala. Keep following the tutorial, you are doing a great job so far!\\n\");\n"
        },
        "id": 179057403958711993733277794052454578827,
        "message": "Line contains following spacing inconsistencies:\n- Trailing whitespaces.",
        "message_arguments": {},
        "message_base": "Line contains following spacing inconsistencies:\n- Trailing whitespaces.",
        "origin": "SpaceConsistencyBear",
        "severity": 1
      }
    ]
  }

All 5 comments

The best thing I can think of is writing a language server that reads the .coafile and converts it to LSP JSON as specified here: https://microsoft.github.io/language-server-protocol/specification.

Is there any such implementation or an example of such conversions that can help me?

@KVGarg It sounds to me like you would have to do the following based on the JSON output:

  1. Convert the line number/ranges of the warning/error/whatever in affected_code.
  2. Convert the message in message.
  3. Optionally convert severity.
  4. Use affected_code to identify the relevant Location of the file.

This is how I would start anyway. Does that help?

{
  "results": {
    "cli": [
      {
        "additional_info": "Your source code contains trailing whitespaces. Those usually have no meaning. Please consider removing them.",
        "affected_code": [
          {
            "end": {
              "column": null,
              "file": "/app/src/main.c",
              "line": 1
            },
            "file": "/app/src/main.c",
            "start": {
              "column": null,
              "file": "/app/src/main.c",
              "line": 1
            }
          }
        ],
        "aspect": "NoneType",
        "confidence": 100,
        "debug_msg": "",
        "diffs": {
          "/app/src/main.c": "--- \n+++ \n@@ -1,4 +1,4 @@\n-#include <stdio.h> \n+#include <stdio.h>\n \n int main(void) {\n     printf(\"Welcome to coala. Keep following the tutorial, you are doing a great job so far!\\n\");\n"
        },
        "id": 179057403958711993733277794052454578827,
        "message": "Line contains following spacing inconsistencies:\n- Trailing whitespaces.",
        "message_arguments": {},
        "message_base": "Line contains following spacing inconsistencies:\n- Trailing whitespaces.",
        "origin": "SpaceConsistencyBear",
        "severity": 1
      }
    ]
  }

Does that help?

@dbaeumer @rcjsuen Thnx for such great help. It actually gave me a clear path on how to achieve my goal. Thank U so much :+1: :innocent:

You are welcome.

I will close the issue then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eskibear picture Eskibear  路  3Comments

ljw1004 picture ljw1004  路  3Comments

Khaos66 picture Khaos66  路  5Comments

felixfbecker picture felixfbecker  路  3Comments

svenefftinge picture svenefftinge  路  5Comments