Skip to content

Commit

Permalink
Merge pull request #30 from ConnorJennison/hoverRuby
Browse files Browse the repository at this point in the history
Add ENV hover support for ruby
  • Loading branch information
motdotla committed Sep 19, 2022
2 parents a800355 + 6ddb920 commit 19affb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/peeking.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const run = function (context) {
const javascriptreactHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'javascriptreact' }, providers.javascriptHover)
const typescriptreactHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'typescriptreact' }, providers.javascriptHover)
const vueHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'vue' }, providers.javascriptHover)

const rubyHover = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'ruby' }, providers.rubyHover)

context.subscriptions.push(javascriptHover)
context.subscriptions.push(typescriptHover)
context.subscriptions.push(javascriptreactHover)
Expand Down
26 changes: 26 additions & 0 deletions lib/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ const javascriptHover = {
}
}

const rubyHover = {
provideHover: function (document, position, token) {
const reg = /ENV\["([A-Z]{1}[A-Z_0123456789]+)"\]/
const line = document.lineAt(position).text
const matches = line.match(reg)

if (!matches) {
return undefined
} else {
const key = matches[1]

const start = line.indexOf(key)
const end = start + key.length
if (position.character >= start && position.character <= end) {
const parsed = helpers.envParsed()
const value = parsed[key]

return new vscode.Hover(value)
} else {
return undefined
}
}
}
}

const javascriptCompletion = {
provideCompletionItems: function (document, position) {
const linePrefix = document.lineAt(position).text.slice(0, position.character)
Expand Down Expand Up @@ -88,5 +113,6 @@ const viewDotenvNew = {
}

module.exports.javascriptHover = javascriptHover
module.exports.rubyHover = rubyHover
module.exports.javascriptCompletion = javascriptCompletion
module.exports.viewDotenvNew = viewDotenvNew

0 comments on commit 19affb6

Please sign in to comment.