Skip to content

custom LSP requests #611

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

## master

#### :nail_care: Polish

- Rename custom LSP methods names. https://github.com/rescript-lang/rescript-vscode/pull/611

#### :bug: Bug Fix

- Fix issue where `-open Some.Path` in `"bsc-flags"` would sometimes be treated differently from `open Some.Path` locally in a file https://github.com/rescript-lang/rescript-vscode/pull/616
Expand Down
11 changes: 4 additions & 7 deletions client/src/commands/create_interface.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import * as fs from "fs";
import * as p from "vscode-languageserver-protocol";
import { LanguageClient, RequestType } from "vscode-languageclient/node";
import { window } from "vscode";

interface CreateInterfaceRequestParams {
uri: string;
}

export const createInterfaceRequest = new RequestType<
CreateInterfaceRequestParams,
string,
p.TextDocumentIdentifier,
p.TextDocumentIdentifier,
void
>("rescript-vscode.create_interface");
>("textDocument/createInterface");

export const createInterface = (client: LanguageClient) => {
if (!client) {
Expand Down
17 changes: 5 additions & 12 deletions client/src/commands/open_compiled.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import * as fs from "fs";
import * as p from "vscode-languageserver-protocol";
import { window, Uri, ViewColumn } from "vscode";
import { LanguageClient, RequestType } from "vscode-languageclient/node";

interface OpenCompiledFileRequestParams {
uri: string;
}

interface OpenCompiledFileResponseParams {
uri: string;
}

let openCompiledFileRequest = new RequestType<
OpenCompiledFileRequestParams,
OpenCompiledFileResponseParams,
p.TextDocumentIdentifier,
p.TextDocumentIdentifier,
void
>("rescript-vscode.open_compiled");
>("textDocument/openCompiled");

export const openCompiled = (client: LanguageClient) => {
if (!client) {
Expand All @@ -36,7 +29,7 @@ export const openCompiled = (client: LanguageClient) => {
uri: editor.document.uri.toString(),
})
.then((response) => {
const document = Uri.file(response.uri);
const document = Uri.parse(response.uri);

return window.showTextDocument(document, {
viewColumn: ViewColumn.Beside,
Expand Down
36 changes: 14 additions & 22 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,17 @@ let findPlatformPath = (projectRootPath: p.DocumentUri | null) => {
let findBscExeBinary = (projectRootPath: p.DocumentUri | null) =>
utils.findBinary(findPlatformPath(projectRootPath), c.bscExeName);

interface CreateInterfaceRequestParams {
uri: string;
}

let createInterfaceRequest = new v.RequestType<
CreateInterfaceRequestParams,
string,
p.TextDocumentIdentifier,
p.TextDocumentIdentifier,
void
>("rescript-vscode.create_interface");

interface OpenCompiledFileParams {
uri: string;
}
>("textDocument/createInterface");

let openCompiledFileRequest = new v.RequestType<
OpenCompiledFileParams,
OpenCompiledFileParams,
p.TextDocumentIdentifier,
p.TextDocumentIdentifier,
void
>("rescript-vscode.open_compiled");
>("textDocument/openCompiled");

let getCurrentCompilerDiagnosticsForFile = (
fileUri: string
Expand Down Expand Up @@ -859,7 +851,7 @@ let updateDiagnosticSyntax = (fileUri: string, fileContent: string) => {
};

function createInterface(msg: p.RequestMessage): p.Message {
let params = msg.params as CreateInterfaceRequestParams;
let params = msg.params as p.TextDocumentIdentifier;
let extension = path.extname(params.uri);
let filePath = fileURLToPath(params.uri);
let projDir = utils.findProjectRootOfFile(filePath);
Expand Down Expand Up @@ -953,7 +945,9 @@ function createInterface(msg: p.RequestMessage): p.Message {
let response: p.ResponseMessage = {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result: "Interface successfully created.",
result: {
uri: utils.pathToURI(resiPath)
},
};
return response;
} catch (e) {
Expand All @@ -970,7 +964,7 @@ function createInterface(msg: p.RequestMessage): p.Message {
}

function openCompiledFile(msg: p.RequestMessage): p.Message {
let params = msg.params as OpenCompiledFileParams;
let params = msg.params as p.TextDocumentIdentifier;
let filePath = fileURLToPath(params.uri);
let projDir = utils.findProjectRootOfFile(filePath);

Expand Down Expand Up @@ -1014,14 +1008,12 @@ function openCompiledFile(msg: p.RequestMessage): p.Message {
return response;
}

let result: OpenCompiledFileParams = {
uri: compiledFilePath.result,
};

let response: p.ResponseMessage = {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result,
result: {
uri: utils.pathToURI(compiledFilePath.result),
}
};

return response;
Expand Down
2 changes: 1 addition & 1 deletion server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export let runBuildWatcherUsingValidBuildPath = (
*/

// parser helpers
let pathToURI = (file: string) => {
export let pathToURI = (file: string) => {
return process.platform === "win32" ? `file:\\\\\\${file}` : `file://${file}`;
};
let parseFileAndRange = (fileAndRange: string) => {
Expand Down