From 33f7ecb2b28655eb1be2b8f5f98f2a751887f15b Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 8 Oct 2023 19:17:37 -0300 Subject: [PATCH] docgen: polish --- analysis/src/DocExtraction.ml | 4 +-- client/src/commands.ts | 1 - client/src/commands/extract_docs.ts | 50 ----------------------------- client/src/extension.ts | 3 -- package.json | 4 --- server/src/server.ts | 25 --------------- 6 files changed, 2 insertions(+), 85 deletions(-) delete mode 100644 client/src/commands/extract_docs.ts diff --git a/analysis/src/DocExtraction.ml b/analysis/src/DocExtraction.ml index 4ea095755..e1ca613bc 100644 --- a/analysis/src/DocExtraction.ml +++ b/analysis/src/DocExtraction.ml @@ -237,7 +237,7 @@ let extractDocs ~path ~debug = FindFiles.isImplementation path = false && FindFiles.isInterface path = false then ( - Printf.printf "error: failed to read %s, expected an .res or .resi file\n" + Printf.eprintf "error: failed to read %s, expected an .res or .resi file\n" path; exit 1); let path = @@ -256,7 +256,7 @@ let extractDocs ~path ~debug = in match Cmt.loadFullCmtFromPath ~path with | None -> - Printf.printf + Printf.eprintf "error: failed to generate doc for %s, try to build the project\n" path; exit 1 | Some full -> diff --git a/client/src/commands.ts b/client/src/commands.ts index 8acb2dc81..98bcec00d 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -6,7 +6,6 @@ import { } from "./commands/code_analysis"; export { createInterface } from "./commands/create_interface"; -export { extractDocs } from "./commands/extract_docs"; export { openCompiled } from "./commands/open_compiled"; export { switchImplIntf } from "./commands/switch_impl_intf"; diff --git a/client/src/commands/extract_docs.ts b/client/src/commands/extract_docs.ts deleted file mode 100644 index 3d9f295a4..000000000 --- a/client/src/commands/extract_docs.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as p from "vscode-languageserver-protocol"; -import { LanguageClient, RequestType } from "vscode-languageclient/node"; -import { Position, Uri, window, workspace, WorkspaceEdit } from "vscode"; -import path = require("path"); - -export const extractDocsRequest = new RequestType< - p.TextDocumentIdentifier, - string, - void ->("textDocument/extractDocs"); - -export const extractDocs = async (client: LanguageClient) => { - if (!client) { - return window.showInformationMessage("Language server not running"); - } - - const editor = window.activeTextEditor; - - if (!editor) { - return window.showInformationMessage("No active editor"); - } - - try { - const docUri = editor.document.uri.toString(); - const res = await client.sendRequest(extractDocsRequest, { - uri: docUri, - }); - - const newFile = Uri.parse( - "untitled:" + - path.join( - workspace.workspaceFolders[0].uri.fsPath, - `${path.basename(docUri)}.json` - ) - ); - workspace.openTextDocument(newFile).then((document) => { - const edit = new WorkspaceEdit(); - edit.insert(newFile, new Position(0, 0), JSON.stringify(res, null, 2)); - return workspace.applyEdit(edit).then((success) => { - if (success) { - window.showTextDocument(document); - } else { - window.showInformationMessage("Error!"); - } - }); - }); - } catch (e) { - console.error("failed", e); - } -}; diff --git a/client/src/extension.ts b/client/src/extension.ts index 419a8251f..e1b77c40f 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -201,9 +201,6 @@ export function activate(context: ExtensionContext) { customCommands.openCompiled(client); }); - commands.registerCommand("rescript-vscode.extract_docs", () => { - customCommands.extractDocs(client); - }); commands.registerCommand( "rescript-vscode.go_to_location", diff --git a/package.json b/package.json index b357bfdac..f68f74ea4 100644 --- a/package.json +++ b/package.json @@ -49,10 +49,6 @@ "command": "rescript-vscode.create_interface", "title": "ReScript: Create an interface file for this implementation file" }, - { - "command": "rescript-vscode.extract_docs", - "title": "ReScript: Extract documentation as JSON for file." - }, { "command": "rescript-vscode.open_compiled", "category": "ReScript", diff --git a/server/src/server.ts b/server/src/server.ts index ed56de4e7..165a84eef 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -152,11 +152,6 @@ let openCompiledFileRequest = new v.RequestType< void >("textDocument/openCompiled"); -let extractDocsRequest = new v.RequestType< - p.TextDocumentIdentifier, - p.TextDocumentIdentifier, - void ->("textDocument/extractDocs"); let getCurrentCompilerDiagnosticsForFile = ( fileUri: string @@ -971,24 +966,6 @@ function createInterface(msg: p.RequestMessage): p.Message { } } -function extractDocs(msg: p.RequestMessage): p.Message { - let params = msg.params as p.TextDocumentIdentifier; - let filePath = fileURLToPath(params.uri); - - let response = utils.runAnalysisCommand( - filePath, - ["extractDocs", filePath], - msg - ); - - let res: p.ResponseMessage = { - jsonrpc: c.jsonrpcVersion, - id: msg.id, - result: response.result, - }; - return res; -} - function openCompiledFile(msg: p.RequestMessage): p.Message { let params = msg.params as p.TextDocumentIdentifier; let filePath = fileURLToPath(params.uri); @@ -1254,8 +1231,6 @@ function onMessage(msg: p.Message) { send(createInterface(msg)); } else if (msg.method === openCompiledFileRequest.method) { send(openCompiledFile(msg)); - } else if (msg.method === extractDocsRequest.method) { - send(extractDocs(msg)); } else if (msg.method === p.InlayHintRequest.method) { let params = msg.params as InlayHintParams; let extName = path.extname(params.textDocument.uri);