- Notifications
You must be signed in to change notification settings - Fork61
Hook up command from rescript-editor-support.#14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
a27a625 runDumpCommand
cristianoc450dc34 Add support for autocompletion command.
cristianoce2193e4 Look for the binary in `server/__platform__/bin.exe` and vendor darwi…
cristianocf9093ba Register capabilities only if binary exists.
cristianocfad4a7b Binary now called rescript-editor-support.exe.
cristianocf9278ef Vendor rescript-editor-support.exe for linxu and win32 too.
cristianoc1a58d0c Sync up rescript-editor-support
cristianocc42f6e2 rescript-editor-support now uses stdout
cristianocFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Binary file addedserver/darwin/rescript-editor-support.exe
Binary file not shown.
Binary file addedserver/linux/rescript-editor-support.exe
Binary file not shown.
90 changes: 90 additions & 0 deletionsserver/src/RescriptEditorSupport.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { fileURLToPath } from "url"; | ||
| import { RequestMessage } from "vscode-languageserver"; | ||
| import * as utils from "./utils"; | ||
| import * as path from "path"; | ||
| import { exec } from "child_process"; | ||
| import * as tmp from "tmp"; | ||
| import fs from "fs"; | ||
| let binaryPath = path.join( | ||
| path.dirname(__dirname), | ||
| process.platform, | ||
| "rescript-editor-support.exe" | ||
| ); | ||
| export let binaryExists = fs.existsSync(binaryPath); | ||
| let findExecutable = (uri: string) => { | ||
| let filePath = fileURLToPath(uri); | ||
| let projectRootPath = utils.findProjectRootOfFile(filePath); | ||
| if (projectRootPath == null || !binaryExists) { | ||
| return null; | ||
| } else { | ||
| return { binaryPath, filePath, cwd: projectRootPath }; | ||
| } | ||
| }; | ||
| export function runDumpCommand( | ||
| msg: RequestMessage, | ||
| onResult: ( | ||
| result: { hover?: string; definition?: { uri?: string; range: any } } | null | ||
| ) => void | ||
| ) { | ||
| let executable = findExecutable(msg.params.textDocument.uri); | ||
| if (executable == null) { | ||
| onResult(null); | ||
| } else { | ||
| let command = | ||
| executable.binaryPath + | ||
| " dump " + | ||
| executable.filePath + | ||
| ":" + | ||
| msg.params.position.line + | ||
| ":" + | ||
| msg.params.position.character; | ||
| exec(command, { cwd: executable.cwd }, function (_error, stdout, _stderr) { | ||
| let result = JSON.parse(stdout); | ||
| if (result && result[0]) { | ||
| onResult(result[0]); | ||
| } else { | ||
| onResult(null); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| export function runCompletionCommand( | ||
| msg: RequestMessage, | ||
| code: string, | ||
| onResult: (result: [{ label: string }] | null) => void | ||
| ) { | ||
| let executable = findExecutable(msg.params.textDocument.uri); | ||
| if (executable == null) { | ||
| onResult(null); | ||
| } else { | ||
| let tmpobj = tmp.fileSync(); | ||
| let tmpname = tmpobj.name; | ||
| fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); | ||
| let command = | ||
| executable.binaryPath + | ||
| " complete " + | ||
| executable.filePath + | ||
| ":" + | ||
| msg.params.position.line + | ||
| ":" + | ||
| msg.params.position.character + | ||
| " " + | ||
| tmpname; | ||
| exec(command, { cwd: executable.cwd }, function (_error, stdout, _stderr) { | ||
| tmpobj.removeCallback(); | ||
| let result = JSON.parse(stdout); | ||
| if (result && result[0]) { | ||
| onResult(result); | ||
| } else { | ||
| onResult(null); | ||
| } | ||
| }); | ||
| } | ||
| } |
74 changes: 59 additions & 15 deletionsserver/src/server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Binary file addedserver/win32/rescript-editor-support.exe
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.