summaryrefslogtreecommitdiff
path: root/src/dged/lsp.h
blob: 32d00bc997a6a45da18f69212e15bb9bb820fd49 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef _LSP_H
#define _LSP_H

#include <stddef.h>

#include "json.h"
#include "jsonrpc.h"
#include "location.h"
#include "s8.h"

struct buffer;
struct lsp;
struct reactor;

typedef uint64_t request_id;

struct lsp_response_error {
  int code;
  struct s8 message;
  struct json_value data;
};

enum lsp_message_type {
  Lsp_Notification,
  Lsp_Request,
  Lsp_Response,
};

struct lsp_response {
  request_id id;

  bool ok;
  union data {
    struct json_value result;
    struct lsp_response_error error;
  } value;
};

struct lsp_request {
  request_id id;
  struct s8 method;
  struct json_value params;
};

struct lsp_notification {
  struct s8 method;
  struct json_value params;
};

struct lsp_message {
  enum lsp_message_type type;
  bool parsed;
  union message_data {
    struct lsp_response response;
    struct lsp_request request;
    struct lsp_notification notification;
  } message;

  struct s8 payload;
  struct jsonrpc_message jsonrpc_msg;
};

// lifecycle functions
struct lsp *lsp_create(char *const command[], struct reactor *reactor,
                       struct buffer *stderr_buffer, const char *name);
uint32_t lsp_update(struct lsp *lsp, struct lsp_message *msgs,
                    uint32_t nmax_msgs);
void lsp_destroy(struct lsp *lsp);

// process control functions
int lsp_start_server(struct lsp *lsp);
int lsp_restart_server(struct lsp *lsp);
void lsp_stop_server(struct lsp *lsp);
bool lsp_server_running(const struct lsp *lsp);
uint64_t lsp_server_pid(const struct lsp *lsp);
const char *lsp_server_name(const struct lsp *lsp);

// lsp message creation
struct lsp_message lsp_create_request(request_id id, struct s8 method,
                                      struct s8 payload);
struct lsp_message lsp_create_notification(struct s8 method, struct s8 payload);
struct lsp_message lsp_create_response(request_id id, bool ok,
                                       struct s8 payload);

void lsp_message_destroy(struct lsp_message *message);

// protocol functions
void lsp_send(struct lsp *lsp, struct lsp_message message);

#endif