Racket Language Server
(require racket-language-server) | |
package: racket-language-server |
Implementation of the Language Server Protocol for Racket.
1 Custom Extensions
1.1 Colorize Notification
Colorize notifications are sent from the server to the client to enable semantic syntax highlighting.
When a file changes it is the server’s responsibility to re-compute syntax highlighting and push them to the client. Newly pushed tokens always replace previously pushed tokens. There is no merging that happens on the client side.
method: ’racket/colorize’
params: ‘RacketColorizeParams‘ defined as follows:
interface RacketColorizeParams { |
/** |
* The URI for which colorization is reported. |
*/ |
uri: DocumentUri; |
|
/** |
* An array of diagnostic information items. |
*/ |
tokens: RacketToken[]; |
} |
|
interface RacketToken { |
/** |
* The kind of token. |
*/ |
kind: RacketTokenKind; |
|
/** |
* The lexer mode used. |
*/ |
mode: RacketLexerMode; |
|
/** |
* Range of the token. |
*/ |
range: Range; |
} |
|
enum RacketLexerMode { |
Racket = "racket", |
Scribble = "scribble", |
Other = "other" |
} |
|
enum RacketTokenKind { |
// Generic token kinds |
Symbol = "symbol", |
Keyword = "keyword", |
Comment = "comment", |
String = "string", |
Constant = "constant", |
Parenthesis = "parenthesis", |
Error = "error", |
NoColor = "no-color", |
Other = "other", |
// Racket token kinds |
HashColonKeyword = "hash-colon-keyword", |
SexpComment = "sexp-comment", |
// Racket semantic token kinds |
Imported = "imported", |
LexicallyBound = "lexically-bound", |
Free = "free", |
Set!d = "set!d", |
// Scribble token kinds |
Text = "text" |
} |
1.2 Indent Request
Indent requests are sent from the client to the server to compute the indentation for a line number.
method: ’racket/indent’
params: ‘RacketIndentParams‘ defined as follows:
interface RacketIndentParams { |
/** |
* The TextDocument for which indentation is requested. |
*/ |
textDocument: TextDocumentIdentifier; |
|
/** |
* The line to indent. |
*/ |
line: number; |
} |
result: ‘number‘
error: code and message set in case an exception happens during the definition request.
2 Application Programming Interface
The codebase is split in two folders, ‘lang‘ which provides Racket language support procedures that extract and combine information from drracket and other sources and ‘protocol‘ which converts the information to the Language Server Protocol.
2.1 Language support
struct
(struct token (lexeme type data start end mode offset) #:extra-constructor-name make-token) lexeme : any/c type : (or/c symbol? false/c) data : any/c start : (or/c exact-nonnegative-integer? false/c) end : (or/c exact-nonnegative-integer? false/c) mode : (or/c (one-of/c 'racket 'scribble 'lang 'other) false/c) offset : (or/c exact-integer? false/c)
procedure
(eof-token? tok) → boolean?
tok : any/c
procedure
in : input-port?
procedure
(make-tokenizer str) → (-> struct?)
str : string?
procedure
(apply-tokenizer-maker tokenizer val) → (listof struct?)
tokenizer : (-> string? (-> struct?)) val : string?
procedure
(list->producer tokens) → generator?
tokens : (listof struct?)
procedure
(lang-tokenizer next-token) → (-> struct?)
next-token : (-> struct?)
procedure
(skip-white next-token) → (-> struct?)
next-token : (-> struct?)
procedure
(sexp-comment-reclassifier next-token) → (-> struct?)
next-token : (-> struct?)
procedure
(token-stream-matcher old-tokens)
→ (-> (-> struct?) (-> struct?)) old-tokens : (listof struct?)
procedure
(semantic-reclassifier intervals [ old-intervals]) → (-> (-> struct?) (-> struct?)) intervals : interval-map? old-intervals : boolean? = #f
2.2 Protocol
3 References
[0] https://microsoft.github.io/language-server-protocol/specification
[1] https://docs.racket-lang.org/tools/lang-languages-customization.html
4 License
Copyright 2018 David Craven and others
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.