diff --git a/CHANGELOG.md b/CHANGELOG.md index 458fb21..fe69204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,13 @@ ## master **Improvements:** -- Add syntax support for int polyvariants -- Updated vendored rescript-vscode server to `1.1.2` (see changes [here](https://github.com/rescript-lang/rescript-vscode/blob/master/CHANGELOG.md#112)) - - Rename support for let-binding, types, record labels, module names etc - - **Important:** If you are using coc.nvim, make sure to upgrade to the latest `release` version first, otherwise renaming will not work across files! +- Add syntax highlighting for int polyvariants - Improved syntax highlighting for string interpolation ([#44](https://github.com/rescript-lang/vim-rescript/pull/44)) +- Updated vendored rescript-vscode server to `1.1.3` (see changes introduced in [1.1.2](https://github.com/rescript-lang/rescript-vscode/blob/master/CHANGELOG.md#112) and [1.1.3](https://github.com/rescript-lang/rescript-vscode/blob/master/CHANGELOG.md#113)) + - Rename support for let-binding, types, record labels, module names etc + - **Important:** If you are using coc.nvim, make sure to upgrade to coc's latest `release` version first, otherwise renaming will not work across files! + - Jump to type definition support + - New jump-to-definition behavior when having `.res` and `.resi` files in place ## 2.0.1 diff --git a/examples/rescript-project/package-lock.json b/examples/rescript-project/package-lock.json index 3d95d88..ea0fd47 100644 --- a/examples/rescript-project/package-lock.json +++ b/examples/rescript-project/package-lock.json @@ -1,13 +1,35 @@ { "name": "rescript-project", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "rescript": "9.1.3" + } + }, + "node_modules/rescript": { + "version": "9.1.3", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-9.1.3.tgz", + "integrity": "sha512-TpfW3DakgCJtWbRvAek7cysuikBWarjqt8PrbFg0Rk3O+o4dt0inBdxyZe/+u3LOAWzyKK+2UlqC0xiCBgs6pQ==", + "dev": true, + "hasInstallScript": true, + "bin": { + "bsc": "bsc", + "bsrefmt": "bsrefmt", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } + } + }, "dependencies": { "rescript": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/rescript/-/rescript-9.1.2.tgz", - "integrity": "sha512-4wHvTDv3nyYnAPJHcg1RGG8z7u3HDiBf6RN3P/dITDv859Qo35aKOzJWQtfBzbAs0EKNafLqei3TnUqiAv6BwQ==", + "version": "9.1.3", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-9.1.3.tgz", + "integrity": "sha512-TpfW3DakgCJtWbRvAek7cysuikBWarjqt8PrbFg0Rk3O+o4dt0inBdxyZe/+u3LOAWzyKK+2UlqC0xiCBgs6pQ==", "dev": true } } diff --git a/examples/rescript-project/package.json b/examples/rescript-project/package.json index 34564cc..dfc6986 100644 --- a/examples/rescript-project/package.json +++ b/examples/rescript-project/package.json @@ -10,6 +10,6 @@ "author": "", "license": "ISC", "devDependencies": { - "rescript": "9.1.2" + "rescript": "9.1.3" } } diff --git a/examples/rescript-project/src/TestJumpTo.res b/examples/rescript-project/src/TestJumpTo.res new file mode 100644 index 0000000..a778783 --- /dev/null +++ b/examples/rescript-project/src/TestJumpTo.res @@ -0,0 +1,6 @@ +Demo.a->Js.log +Demo.b->Js.log + +let user = {RecordExample.User.name: "test"} + +RecordExample.logUser(user) diff --git a/examples/rescript-project/src/interpolationSyntax.res b/examples/rescript-project/src/interpolationSyntax.res index 4691fe4..50d5a69 100644 --- a/examples/rescript-project/src/interpolationSyntax.res +++ b/examples/rescript-project/src/interpolationSyntax.res @@ -8,4 +8,4 @@ let var3 = j`hello $name how you doin?` let varInvalid = `hello $name how you doin?` -let expr = `2 + 2 is ${Int.toString(2 + 2)}` +let expr = `2 + 2 is ${Belt.Int.toString(2 + 2)}` diff --git a/examples/rescript-project/src/polySyntax.res b/examples/rescript-project/src/polySyntax.res index 71d1d48..bf70396 100644 --- a/examples/rescript-project/src/polySyntax.res +++ b/examples/rescript-project/src/polySyntax.res @@ -7,3 +7,5 @@ let c = #"legacy exo-tic" let d = #732 let e = {RecordExample.User.name: "test"} + +Demo.a->Js.log diff --git a/examples/rescript-project/src/recordExample.res b/examples/rescript-project/src/recordExample.res index eea22db..c06e015 100644 --- a/examples/rescript-project/src/recordExample.res +++ b/examples/rescript-project/src/recordExample.res @@ -6,12 +6,11 @@ module Role = { type t = {roleName: string} } -let doSomething = (u: User.t) => { +let logUser = (u: User.t) => { Js.log(u.name) } -let other = (r: Role.t) => { +let logRole = (r: Role.t) => { Js.log(r.roleName) } - diff --git a/examples/rescript-project/src/recordExample.resi b/examples/rescript-project/src/recordExample.resi new file mode 100644 index 0000000..6cc004f --- /dev/null +++ b/examples/rescript-project/src/recordExample.resi @@ -0,0 +1,11 @@ +module User: { + type t = {name: string} +} + +module Role: { + type t = {roleName: string} +} + +let logUser: User.t => unit + +let logRole: Role.t => unit diff --git a/server/analysis_binaries/darwin/rescript-editor-analysis.exe b/server/analysis_binaries/darwin/rescript-editor-analysis.exe index edfb781..ba73fa9 100755 Binary files a/server/analysis_binaries/darwin/rescript-editor-analysis.exe and b/server/analysis_binaries/darwin/rescript-editor-analysis.exe differ diff --git a/server/analysis_binaries/linux/rescript-editor-analysis.exe b/server/analysis_binaries/linux/rescript-editor-analysis.exe index 13aebf1..d41e49a 100755 Binary files a/server/analysis_binaries/linux/rescript-editor-analysis.exe and b/server/analysis_binaries/linux/rescript-editor-analysis.exe differ diff --git a/server/analysis_binaries/win32/rescript-editor-analysis.exe b/server/analysis_binaries/win32/rescript-editor-analysis.exe index 804afd5..a292710 100755 Binary files a/server/analysis_binaries/win32/rescript-editor-analysis.exe and b/server/analysis_binaries/win32/rescript-editor-analysis.exe differ diff --git a/server/node_modules/.package-lock.json b/server/node_modules/.package-lock.json index 9cf4343..11951e2 100644 --- a/server/node_modules/.package-lock.json +++ b/server/node_modules/.package-lock.json @@ -1,6 +1,6 @@ { "name": "rescript-language-server", - "version": "1.1.1", + "version": "1.1.3", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/server/out/server.js b/server/out/server.js index 3e0b1b8..9ab16a9 100644 --- a/server/out/server.js +++ b/server/out/server.js @@ -230,6 +230,13 @@ function definition(msg) { let response = utils.runAnalysisCommand(filePath, ["definition", filePath, params.position.line, params.position.character], msg); return response; } +function typeDefinition(msg) { + // https://microsoft.github.io/language-server-protocol/specification/specification-current/#textDocument_typeDefinition + let params = msg.params; + let filePath = url_1.fileURLToPath(params.textDocument.uri); + let response = utils.runAnalysisCommand(filePath, ["typeDefinition", filePath, params.position.line, params.position.character], msg); + return response; +} function references(msg) { // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references let params = msg.params; @@ -243,32 +250,55 @@ function references(msg) { }; return response; } -function rename(msg) { - // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename +function prepareRename(msg) { + // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename let params = msg.params; let filePath = url_1.fileURLToPath(params.textDocument.uri); let locations = utils.getReferencesForPosition(filePath, params.position); - let result; - if (locations === null) { - result = null; - } - else { - let changes = {}; - locations.forEach(({ uri, range }) => { - let textEdit = { range, newText: params.newName }; - if (uri in changes) { - changes[uri].push(textEdit); - } - else { - changes[uri] = [textEdit]; + let result = null; + if (locations !== null) { + locations.forEach(loc => { + if (path.normalize(url_1.fileURLToPath(loc.uri)) === + path.normalize(url_1.fileURLToPath(params.textDocument.uri))) { + let { start, end } = loc.range; + let pos = params.position; + if (start.character <= pos.character && + start.line <= pos.line && + end.character >= pos.character && + end.line >= pos.line) { + result = loc.range; + } + ; } }); - result = { changes }; } + ; + return { + jsonrpc: c.jsonrpcVersion, + id: msg.id, + result + }; +} +function rename(msg) { + // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename + let params = msg.params; + let filePath = url_1.fileURLToPath(params.textDocument.uri); + let documentChanges = utils.runAnalysisAfterSanityCheck(filePath, [ + "rename", + filePath, + params.position.line, + params.position.character, + params.newName + ]); + let result = null; + if (documentChanges !== null) { + result = { documentChanges }; + } + ; let response = { jsonrpc: c.jsonrpcVersion, id: msg.id, - result, + result }; return response; } @@ -344,7 +374,7 @@ function format(msg) { let code = getOpenedFileContent(params.textDocument.uri); let formattedResult = utils.formatUsingValidBscNativePath(code, bscNativePath, extension === c.resiExt); if (formattedResult.kind === "success") { - let max = formattedResult.result.length; + let max = code.length; let result = [ { range: { @@ -519,9 +549,11 @@ function onMessage(msg) { documentFormattingProvider: true, hoverProvider: true, definitionProvider: true, + typeDefinitionProvider: true, referencesProvider: true, - renameProvider: true, - documentSymbolProvider: false, + renameProvider: { prepareProvider: true }, + // disabled right now until we use the parser to show non-stale symbols per keystroke + // documentSymbolProvider: true, completionProvider: { triggerCharacters: [".", ">", "@", "~"] }, }, }; @@ -574,9 +606,15 @@ function onMessage(msg) { else if (msg.method === p.DefinitionRequest.method) { send(definition(msg)); } + else if (msg.method === p.TypeDefinitionRequest.method) { + send(typeDefinition(msg)); + } else if (msg.method === p.ReferencesRequest.method) { send(references(msg)); } + else if (msg.method === p.PrepareRenameRequest.method) { + send(prepareRename(msg)); + } else if (msg.method === p.RenameRequest.method) { send(rename(msg)); } diff --git a/server/package-lock.json b/server/package-lock.json index b3eef5d..7280483 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "rescript-language-server", - "version": "1.1.1", + "version": "1.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rescript-language-server", - "version": "1.1.1", + "version": "1.1.3", "license": "MIT", "dependencies": { "chokidar": "^3.5.1", diff --git a/server/package.json b/server/package.json index e60c22c..5abd507 100644 --- a/server/package.json +++ b/server/package.json @@ -1,7 +1,7 @@ { "name": "rescript-language-server", "description": "ReScript's language-server", - "version": "1.1.2", + "version": "1.1.3", "author": "chenglou", "license": "MIT", "engines": {