summaryrefslogtreecommitdiff
path: root/src/dged/lsp.h
blob: 3fd62851ba1b4ccf3a7d8c5d1ac3bdac2a9e887c (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
#ifndef _LSP_H
#define _LSP_H

#include "location.h"
#include "s8.h"

struct buffer;
struct lsp;
struct reactor;

typedef uint32_t request_id;

struct lsp_response {
  request_id id;
  bool ok;
  union payload_data {
    void *result;
    struct s8 error;
  } payload;
};

struct lsp_notification {
  int something;
};

struct lsp_client {
  void (*log_message)(int type, struct s8 msg);
};

struct hover {
  struct s8 contents;

  bool has_range;
  struct region *range;
};

struct text_doc_item {
  struct s8 uri;
  struct s8 language_id;
  uint32_t version;
  struct s8 text;
};

struct text_doc_position {
  struct s8 uri;
  struct location pos;
};

struct initialize_params {
  struct s8 client_name;
  struct s8 client_version;
};

// lifecycle functions
struct lsp *lsp_create(char *const command[], struct reactor *reactor,
                       struct buffer *stderr_buffer,
                       struct lsp_client client_impl, const char *name);
uint32_t lsp_update(struct lsp *lsp, struct lsp_response **responses,
                    uint32_t responses_capacity);
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);

// protocol functions
void lsp_initialize(struct lsp *lsp, struct initialize_params);
void lsp_did_open_document(struct lsp *lsp, struct text_doc_item document);
request_id lsp_hover(struct lsp *lsp, struct text_doc_position);

#endif