@@ -17,6 +17,69 @@ using .URIs2
1717
1818JSON. lower (uri:: URI ) = string (uri)
1919
20+ # these are the endpoints of JSON-RPC error codes
21+ # per the LSP spec, no LSP error codes should lie
22+ # between these
23+ const SERVER_ERROR_END = - 32000
24+ const SERVER_ERROR_START = - 32099
25+
26+ # These are existing reserved errors for JSONRPC.jl
27+ # We shouldn't throw these manually
28+ const SERVER_NOT_INITIALIZED = - 32002
29+ const UNKNOWN_ERROR_CODE = - 32001
30+
31+ # LSP specific error codes
32+ # these are the defined ranges for LSP errors
33+ # not real error codes. Custom errors must lie
34+ # outside this range
35+ const LSP_RESERVED_ERROR_START = - 32899
36+ const LSP_RESERVED_ERROR_END = - 32800
37+
38+ const REQUEST_CANCELLED = - 32800
39+ const CONTENT_MODIFIED = - 32801
40+ const SERVER_CANCELLED = - 32802
41+ const REQUEST_FAILED = - 32803
42+
43+ # Specific to our implementation
44+ const NO_DOCUMENT = - 33100
45+ const MISMATCHED_VERSION = - 33101
46+ const SHUTDOWN_REQUEST = - 32600
47+
48+ const ERROR_CODES = (
49+ REQUEST_CANCELLED,
50+ CONTENT_MODIFIED,
51+ SERVER_CANCELLED,
52+ REQUEST_FAILED,
53+ NO_DOCUMENT,
54+ MISMATCHED_VERSION,
55+ SHUTDOWN_REQUEST
56+ )
57+
58+ function __init__ ()
59+ # init JSONRPC error messages
60+ conflicting_codes = filter (ERROR_CODES) do code
61+ ! haskey (JSONRPC. JSONRPCErrorStrings, code) && return false
62+ return JSONRPC. JSONRPCErrorStrings[code] != " ServerError"
63+ end
64+ # if any of the codes we want to use are already set,
65+ # it means we have a conflict with another application
66+ # using JSONRPC.jl at the same time in this process
67+ # warn the user of this, so that they can debug/work around it
68+ if ! isempty (conflicting_codes)
69+ @warn """ JSONRPC Error Codes conflict!
70+
71+ Another library besides LanguageServer.jl is using JSONRPC.jl with conflicting error codes.
72+ LanguageServer.jl will overwrite this with its own state. Faulty behavior/error printing may arise.
73+ """ Codes= conflicting_codes
74+ end
75+
76+ JSONRPC. RPCErrorStrings[REQUEST_CANCELLED] = " RequestCancelled"
77+ JSONRPC. RPCErrorStrings[CONTENT_MODIFIED] = " ContentModified"
78+ JSONRPC. RPCErrorStrings[SERVER_CANCELLED] = " ServerCancelled"
79+ JSONRPC. RPCErrorStrings[REQUEST_FAILED] = " RequestFailed"
80+ nothing
81+ end
82+
2083include (" exception_types.jl" )
2184include (" protocol/protocol.jl" )
2285include (" extensions/extensions.jl" )
0 commit comments