diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eef391..2465e4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,16 @@ All notable changes to the Official Dotenv VS Code extension will be documented in this file. -## [Unreleased](https://github.com/dotenv-org/dotenv-vscode/compare/v0.21.0...master) +## [Unreleased](https://github.com/dotenv-org/dotenv-vscode/compare/v0.22.0...master) +## 0.23.0 + +### Added + +* Added autocomplete and hover support for elixir. [#48](https://github.com/dotenv-org/dotenv-vscode/issues/48) + +### Fixed +* Issue where autocloaking would overwrite other tokenColorCustomization settings resolved [#79](https://github.com/dotenv-org/dotenv-vscode/issues/79) ## 0.22.0 ### Added diff --git a/lib/autocloaking.js b/lib/autocloaking.js index 4be6d9d..9c16cc8 100644 --- a/lib/autocloaking.js +++ b/lib/autocloaking.js @@ -41,10 +41,11 @@ function hideValues () { } newRules.push(newRule) // add new rule - const value = { - textMateRules: newRules - } + // Update the textMateRules without changing the other tokenColorCustomization values (issue #79) + const value = config + value.textMateRules = newRules vscode.workspace.getConfiguration().update(section(), value, vscode.ConfigurationTarget.Global) + } catch (e) { console.log(e) } @@ -71,9 +72,9 @@ function unhideValues () { } } - const value = { - textMateRules: newRules - } + // Update textMateRules without deleting other tokenColorCustomization settings (issue #79) + const value = config + value.textMateRules = newRules vscode.workspace.getConfiguration().update(section(), value, vscode.ConfigurationTarget.Global) return true diff --git a/lib/autocompletion.js b/lib/autocompletion.js index add46a2..5133a3d 100644 --- a/lib/autocompletion.js +++ b/lib/autocompletion.js @@ -18,6 +18,7 @@ const run = function (context) { const rust = vscode.languages.registerCompletionItemProvider({ scheme: 'file', language: 'rust' }, providers.rustCompletion, '(') const dart = vscode.languages.registerCompletionItemProvider({ scheme: 'file', language: 'dart' }, providers.dartCompletion, '(') const kotlin = vscode.languages.registerCompletionItemProvider({ scheme: 'file', language: 'kotlin' }, providers.kotlinCompletion, '(') + const elixir = vscode.languages.registerCompletionItemProvider({ scheme: 'file', language: 'elixir' }, providers.elixirCompletion, '(') context.subscriptions.push(javascript) context.subscriptions.push(typescript) @@ -35,6 +36,7 @@ const run = function (context) { context.subscriptions.push(rust) context.subscriptions.push(dart) context.subscriptions.push(kotlin) + context.subscriptions.push(elixir) return true } diff --git a/lib/helpers.js b/lib/helpers.js index 23a946f..90fbbec 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -38,7 +38,8 @@ function hover (language, document, position) { csharp: /Environment.GetEnvironmentVariable\(["']([A-Z]{1}[A-Z_0123456789]+)["']\)/, rust: /std::env::(?:var|var_os)\(["']([A-Z]{1}[A-Z_0123456789]+)["']\)/, dart: /String.fromEnvironment\(["']([A-Z]{1}[A-Z_0123456789]+)["']\)/, - kotlin: /System.getenv\(["']([A-Z]{1}[A-Z_0123456789]+)["']\)/ + kotlin: /System.getenv\(["']([A-Z]{1}[A-Z_0123456789]+)["']\)/, + elixir: /System.get_env\(["']([A-Z]{1}[A-Z_0123456789]+)["']\)/ } const reg = regexDict[language] const line = document.lineAt(position).text diff --git a/lib/peeking.js b/lib/peeking.js index a655350..80ec643 100644 --- a/lib/peeking.js +++ b/lib/peeking.js @@ -16,6 +16,7 @@ const run = function (context) { const rustHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'rust' }, providers.rustHover) const dartHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'dart' }, providers.dartHover) const kotlinHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'kotlin' }, providers.kotlinHover) + const elixirHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'elixir' }, providers.elixirHover) context.subscriptions.push(javascriptHover) context.subscriptions.push(typescriptHover) @@ -31,6 +32,7 @@ const run = function (context) { context.subscriptions.push(rustHover) context.subscriptions.push(dartHover) context.subscriptions.push(kotlinHover) + context.subscriptions.push(elixirHover) return true } diff --git a/lib/providers.js b/lib/providers.js index fab1455..25a49c0 100644 --- a/lib/providers.js +++ b/lib/providers.js @@ -62,6 +62,12 @@ const kotlinHover = { } } +const elixirHover = { + provideHover: function (document, position, token) { + return helpers.hover('elixir', document, position) + } +} + const javascriptCompletion = { provideCompletionItems: function (document, position) { const linePrefix = document.lineAt(position).text.slice(0, position.character) @@ -194,6 +200,17 @@ const kotlinCompletion = { } } +const elixirCompletion = { + provideCompletionItems: function (document, position) { + const linePrefix = document.lineAt(position).text.slice(0, position.character) + if (!linePrefix.endsWith('System.get_env(')) { + return undefined + } + + return helpers.autocomplete('(', document, position) + } +} + const viewDotenvNew = { refresh: function () { return null @@ -220,6 +237,7 @@ module.exports.csharpHover = csharpHover module.exports.rustHover = rustHover module.exports.dartHover = dartHover module.exports.kotlinHover = kotlinHover +module.exports.elixirHover = elixirHover module.exports.javascriptCompletion = javascriptCompletion module.exports.rubyCompletion = rubyCompletion module.exports.pythonCompletion = pythonCompletion @@ -232,4 +250,5 @@ module.exports.csharpCompletion = csharpCompletion module.exports.rustCompletion = rustCompletion module.exports.dartCompletion = dartCompletion module.exports.kotlinCompletion = kotlinCompletion +module.exports.elixirCompletion = elixirCompletion module.exports.viewDotenvNew = viewDotenvNew diff --git a/package-lock.json b/package-lock.json index cd84cff..fb94e8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dotenv-vscode", - "version": "0.22.0", + "version": "0.23.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "dotenv-vscode", - "version": "0.22.0", + "version": "0.23.0", "license": "MIT", "dependencies": { "dotenv": "^16.0.2" diff --git a/package.json b/package.json index 9eac5fc..44ba865 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Dotenv Official +Vault", "description": "Official Dotenv. Auto-cloaking, auto-completion, in-code secret peeking, and more.", "author": "Mot @motdotla", - "version": "0.22.0", + "version": "0.23.0", "license": "MIT", "homepage": "https://github.com/dotenv-org/dotenv-vscode", "icon": "dotenv.png", diff --git a/test/suite/examples/elixir.exs b/test/suite/examples/elixir.exs new file mode 100644 index 0000000..36114b5 --- /dev/null +++ b/test/suite/examples/elixir.exs @@ -0,0 +1,2 @@ +System.get_env("HELLO") +System.get_env( diff --git a/test/suite/lib/providers.test.js b/test/suite/lib/providers.test.js index 53c803f..d3c5ee2 100644 --- a/test/suite/lib/providers.test.js +++ b/test/suite/lib/providers.test.js @@ -358,6 +358,30 @@ describe('providers', function () { }) }) + describe('#elixirCompletion', function () { + it('returns undefined at line 0 and wrong position', async function () { + const elixirFile = path.join(__dirname, '..', 'examples', 'elixir.exs') + const document = await vscode.workspace.openTextDocument(elixirFile) + const position = new vscode.Position(1, 13) + + const result = providers.elixirCompletion.provideCompletionItems(document, position) + + assert.equal(result, undefined) + }) + + it('returns value at line 1 and correct position', async function () { + const elixirFile = path.join(__dirname, '..', 'examples', 'elixir.exs') + const document = await vscode.workspace.openTextDocument(elixirFile) + const position = new vscode.Position(1, 15) + + const result = providers.elixirCompletion.provideCompletionItems(document, position) + + assert.equal(result[0].insertText, '("HELLO"') + assert.equal(result[0].label.label, 'HELLO') + assert.equal(result[0].label.detail, ' World') + }) + }) + describe('#javascriptHover', function () { it('returns undefined at 0 line', async function () { const javascriptFile = path.join(__dirname, '..', 'examples', 'javascript.js') @@ -677,4 +701,26 @@ describe('providers', function () { assert.equal(result.contents[0], 'World') }) }) + + describe('#elixirHover', function () { + it('returns undefined at 0 line with var format', async function () { + const elixirFile = path.join(__dirname, '..', 'examples', 'elixir.exs') + const document = await vscode.workspace.openTextDocument(elixirFile) + const position = new vscode.Position(0, 12) + + const result = providers.elixirHover.provideHover(document, position) + + assert.equal(result, undefined) + }) + + it('returns value at 0 line and correct position', async function () { + const elixirFile = path.join(__dirname, '..', 'examples', 'elixir.exs') + const document = await vscode.workspace.openTextDocument(elixirFile) + const position = new vscode.Position(0, 17) + + const result = providers.elixirHover.provideHover(document, position) + + assert.equal(result.contents[0], 'World') + }) + }) })