forked from jeapostrophe/racket-langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.rkt
51 lines (42 loc) · 1.33 KB
/
interfaces.rkt
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
#lang racket/base
(require (for-syntax racket/base
syntax/parse)
racket/class
racket/contract/base
racket/match
"json-util.rkt")
(define-json-expander Diagnostic
[range any/c]
[severity (or/c 1 2 3 4)]
[source string?]
[message string?])
(define-match-expander Pos
(λ (stx)
(syntax-parse stx
[(_ #:line l #:char c)
(syntax/loc stx
(hash-table ['line (? exact-nonnegative-integer? l)]
['character (? exact-nonnegative-integer? c)]))]))
(λ (stx)
(syntax-parse stx
[(_ #:line l #:char c)
(syntax/loc stx
(hasheq 'line l
'character c))])))
(define-json-expander Range
[start any/c]
[end any/c])
(define (abs-pos->Pos t pos)
(define line (send t position-paragraph pos))
(define line-begin (send t paragraph-start-position line))
(define char (- pos line-begin))
(Pos #:line line #:char char))
(define (Pos->abs-pos t pos)
(match-define (Pos #:line line #:char char) pos)
(line/char->pos t line char))
(define (line/char->pos t line char)
(+ char (send t paragraph-start-position line)))
(define (start/end->Range t start end)
(Range #:start (abs-pos->Pos t start) #:end (abs-pos->Pos t end)))
(struct doc (text trace) #:transparent #:mutable)
(provide (all-defined-out))