Skip to content

Commit

Permalink
Merge pull request #81 from dotenv-org/elixirSupport
Browse files Browse the repository at this point in the history
Elixir support and tokenColorCustomization fix
  • Loading branch information
motdotla committed Mar 22, 2023
2 parents 4cfcca4 + 60f6fc0 commit b9bbb6f
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 11 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lib/autocloaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/autocompletion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/peeking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
19 changes: 19 additions & 0 deletions lib/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions test/suite/examples/elixir.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
System.get_env("HELLO")
System.get_env(
46 changes: 46 additions & 0 deletions test/suite/lib/providers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
})
})
})

0 comments on commit b9bbb6f

Please sign in to comment.