File: json_templates.py

package info (click to toggle)
fortran-language-server 3.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,268 kB
  • sloc: python: 9,688; f90: 1,195; fortran: 30; makefile: 28; ansic: 20
file content (46 lines) | stat: -rw-r--r-- 1,343 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations


def range_json(sln: int, sch: int, eln: int = None, ech: int = None):
    return {
        "range": {
            "start": {"line": sln, "character": sch},
            "end": {"line": eln if eln else sln, "character": ech if ech else sch},
        }
    }


def diagnostic_json(sln: int, sch: int, eln: int, ech: int, msg: str, sev: int):
    return {**range_json(sln, sch, eln, ech), "message": msg, "severity": sev}


def uri_json(uri: str, sln: int, sch: int, eln: int = None, ech: int = None):
    return {"uri": uri, **range_json(sln, sch, eln, ech)}


def location_json(uri: str, sln: int, sch: int, eln: int = None, ech: int = None):
    return {"location": uri_json(uri, sln, sch, eln, ech)}


def symbol_json(
    name: str,
    kind: int,
    uri: str,
    sln: int,
    sch: int,
    eln: int = None,
    ech: int = None,
    container_name: str = None,
):
    if container_name:
        return {
            "name": name,
            "kind": kind,
            **location_json(uri, sln, sch, eln, ech),
            "containerName": container_name,
        }
    return {"name": name, "kind": kind, **location_json(uri, sln, sch, eln, ech)}


def change_json(new_text: str, sln: int, sch: int, eln: int = None, ech: int = None):
    return {**range_json(sln, sch, eln, ech), "newText": new_text}