|
53 | 53 | (logging/info (string/format "`run-diagnostics` is returning this eval-context: %m" env) [:evaluation] 1) |
54 | 54 | [items env])) |
55 | 55 |
|
| 56 | +(def uri-percent-encoding-peg |
| 57 | + ~{:bang (/ (<- "%21") "!") |
| 58 | + :hash (/ (<- "%23") "#") |
| 59 | + :dollar (/ (<- "%24") "$") |
| 60 | + :amp (/ (<- "%26") "&") |
| 61 | + :tick (/ (<- "%27") "'") |
| 62 | + :lparen (/ (<- "%28") "(") |
| 63 | + :rparen (/ (<- "%29") ")") |
| 64 | + :star (/ (<- (* "%2" (+ "A" "a"))) "*") |
| 65 | + :plus (/ (<- (* "%2" (+ "B" "b"))) "+") |
| 66 | + :comma (/ (<- (* "%2" (+ "C" "c"))) ",") |
| 67 | + :slash (/ (<- (* "%2" (+ "F" "f"))) "/") |
| 68 | + :colon (/ (<- (* "%3" (+ "A" "a"))) ":") |
| 69 | + :semi (/ (<- (* "%3" (+ "B" "b"))) ";") |
| 70 | + :equals (/ (<- (* "%3" (+ "D" "d"))) "=") |
| 71 | + :question (/ (<- (* "%3" (+ "F" "f"))) "?") |
| 72 | + :at (/ (<- "%40") "@") |
| 73 | + :lbracket (/ (<- (* "%5" (+ "B" "b"))) "[") |
| 74 | + :rbracket (/ (<- (* "%5" (+ "D" "d"))) "]") |
| 75 | + :main (% (some (+ :bang :hash :dollar :amp :tick :lparen |
| 76 | + :rparen :star :plus :comma :slash :colon |
| 77 | + :semi :equals :question :at :lbracket |
| 78 | + :rbracket '1)))}) |
| 79 | + |
| 80 | +(test (peg/match uri-percent-encoding-peg "file:///c%3A/Users/pete/Desktop/code/libmpsse") |
| 81 | + @["file:///c:/Users/pete/Desktop/code/libmpsse"]) |
| 82 | + |
56 | 83 | (defn on-document-change |
57 | 84 | `` |
58 | 85 | Handler for the ["textDocument/didChange"](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didChange) event. |
|
61 | 88 | `` |
62 | 89 | [state params] |
63 | 90 | (let [content (get-in params ["contentChanges" 0 "text"]) |
64 | | - uri (get-in params ["textDocument" "uri"])] |
| 91 | + uri (first (peg/match uri-percent-encoding-peg |
| 92 | + (get-in params ["textDocument" "uri"])))] |
65 | 93 | (put-in state [:documents uri :content] content) |
66 | 94 |
|
67 | 95 | (if (dyn :push-diagnostics) |
|
75 | 103 | [:noresponse state]))) |
76 | 104 |
|
77 | 105 | (defn on-document-diagnostic [state params] |
78 | | - (let [uri (get-in params ["textDocument" "uri"]) |
| 106 | + (let [uri (first (peg/match uri-percent-encoding-peg |
| 107 | + (get-in params ["textDocument" "uri"]))) |
79 | 108 | content (get-in state [:documents uri :content]) |
80 | 109 | [diagnostics env] (run-diagnostics uri content) |
81 | 110 | message {:kind "full" |
|
85 | 114 | [:ok state message])) |
86 | 115 |
|
87 | 116 | (defn on-document-formatting [state params] |
88 | | - (let [uri (get-in params ["textDocument" "uri"]) |
| 117 | + (let [uri (first (peg/match uri-percent-encoding-peg |
| 118 | + (get-in params ["textDocument" "uri"]))) |
89 | 119 | content (get-in state [:documents uri :content]) |
90 | 120 | new-content (freeze (fmt/format (string/slice content)))] |
91 | 121 | (logging/info (string/format "old content: %m" content) [:formatting] 2) |
|
105 | 135 |
|
106 | 136 | (defn on-document-open [state params] |
107 | 137 | (let [content (get-in params ["textDocument" "text"]) |
108 | | - uri (get-in params ["textDocument" "uri"]) |
| 138 | + uri (first (peg/match uri-percent-encoding-peg |
| 139 | + (get-in params ["textDocument" "uri"]))) |
109 | 140 | [diagnostics env] (run-diagnostics uri content)] |
110 | 141 | (put-in state [:documents uri] @{:content content |
111 | 142 | :eval-env env}) |
|
139 | 170 | :fiber 6 :nil 6)}))) |
140 | 171 |
|
141 | 172 | (defn on-completion [state params] |
142 | | - (let [uri (get-in params ["textDocument" "uri"]) |
| 173 | + (let [uri (first (peg/match uri-percent-encoding-peg |
| 174 | + (get-in params ["textDocument" "uri"]))) |
143 | 175 | eval-env (get-in state [:documents uri :eval-env]) |
144 | 176 | bindings (seq [bind :in (all-bindings eval-env)] |
145 | 177 | (binding-to-lsp-item bind eval-env)) |
|
169 | 201 | [:ok state message])) |
170 | 202 |
|
171 | 203 | (defn on-document-hover [state params] |
172 | | - (let [uri (get-in params ["textDocument" "uri"]) |
| 204 | + (let [uri (first (peg/match uri-percent-encoding-peg |
| 205 | + (get-in params ["textDocument" "uri"]))) |
173 | 206 | content (get-in state [:documents uri :content]) |
174 | 207 | eval-env (get-in state [:documents uri :eval-env]) |
175 | 208 | {"line" line "character" character} (get params "position") |
|
190 | 223 | (logging/info (string/format "%q" state) [:signature]) |
191 | 224 | (logging/info (string "on-signature-help params: ") [:signature]) |
192 | 225 | (logging/info (string/format "%q" params) [:signature]) |
193 | | - (let [uri (get-in params ["textDocument" "uri"]) |
| 226 | + (let [uri (first (peg/match uri-percent-encoding-peg |
| 227 | + (get-in params ["textDocument" "uri"]))) |
194 | 228 | content (get-in state [:documents uri :content]) |
195 | 229 | eval-env (get-in state [:documents uri :eval-env]) |
196 | 230 | {"line" line "character" character} (get params "position") |
|
267 | 301 | Called by the LSP client to request the location of a symbol's definition. |
268 | 302 | `` |
269 | 303 | [state params] |
270 | | - (let [request-uri (get-in params ["textDocument" "uri"]) |
| 304 | + (let [request-uri (first (peg/match uri-percent-encoding-peg |
| 305 | + (get-in params ["textDocument" "uri"]))) |
271 | 306 | content (get-in state [:documents request-uri :content]) |
272 | 307 | eval-env (get-in state [:documents request-uri :eval-env]) |
273 | 308 | {"line" line "character" character} (get params "position") |
|
0 commit comments