diff options
author | David Lattimore <[email protected]> | 2020-07-22 06:00:28 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-24 12:34:00 +0100 |
commit | 3975952601888d9f77e466c12e8e389748984b33 (patch) | |
tree | e599abf34b90be63e091ea78bfa58fe46cf1b81a /editors | |
parent | 02fc3d50ee4d179cc5a443a790544c2a5e439cb0 (diff) |
SSR: Pass current file position through to SSR code.
In a subsequent commit, it will be used for resolving paths.
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/commands.ts | 14 | ||||
-rw-r--r-- | editors/code/src/lsp_ext.ts | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 1f3a7cf7e..3ae995705 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -185,15 +185,21 @@ export function parentModule(ctx: Ctx): Cmd { | |||
185 | 185 | ||
186 | export function ssr(ctx: Ctx): Cmd { | 186 | export function ssr(ctx: Ctx): Cmd { |
187 | return async () => { | 187 | return async () => { |
188 | const editor = vscode.window.activeTextEditor; | ||
188 | const client = ctx.client; | 189 | const client = ctx.client; |
189 | if (!client) return; | 190 | if (!editor || !client) return; |
191 | |||
192 | const position = editor.selection.active; | ||
193 | let textDocument = { uri: editor.document.uri.toString() }; | ||
190 | 194 | ||
191 | const options: vscode.InputBoxOptions = { | 195 | const options: vscode.InputBoxOptions = { |
192 | value: "() ==>> ()", | 196 | value: "() ==>> ()", |
193 | prompt: "Enter request, for example 'Foo($a) ==> Foo::new($a)' ", | 197 | prompt: "Enter request, for example 'Foo($a) ==> Foo::new($a)' ", |
194 | validateInput: async (x: string) => { | 198 | validateInput: async (x: string) => { |
195 | try { | 199 | try { |
196 | await client.sendRequest(ra.ssr, { query: x, parseOnly: true }); | 200 | await client.sendRequest(ra.ssr, { |
201 | query: x, parseOnly: true, textDocument, position, | ||
202 | }); | ||
197 | } catch (e) { | 203 | } catch (e) { |
198 | return e.toString(); | 204 | return e.toString(); |
199 | } | 205 | } |
@@ -208,7 +214,9 @@ export function ssr(ctx: Ctx): Cmd { | |||
208 | title: "Structured search replace in progress...", | 214 | title: "Structured search replace in progress...", |
209 | cancellable: false, | 215 | cancellable: false, |
210 | }, async (_progress, _token) => { | 216 | }, async (_progress, _token) => { |
211 | const edit = await client.sendRequest(ra.ssr, { query: request, parseOnly: false }); | 217 | const edit = await client.sendRequest(ra.ssr, { |
218 | query: request, parseOnly: false, textDocument, position | ||
219 | }); | ||
212 | 220 | ||
213 | await vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edit)); | 221 | await vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edit)); |
214 | }); | 222 | }); |
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 5f32cb40e..149f9a0d6 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts | |||
@@ -93,6 +93,8 @@ export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void | |||
93 | export interface SsrParams { | 93 | export interface SsrParams { |
94 | query: string; | 94 | query: string; |
95 | parseOnly: boolean; | 95 | parseOnly: boolean; |
96 | textDocument: lc.TextDocumentIdentifier; | ||
97 | position: lc.Position; | ||
96 | } | 98 | } |
97 | export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>('experimental/ssr'); | 99 | export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>('experimental/ssr'); |
98 | 100 | ||