Skip to content
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

06. 悬停提示—例子 #6

Open
PDKSophia opened this issue Feb 4, 2021 · 0 comments
Open

06. 悬停提示—例子 #6

PDKSophia opened this issue Feb 4, 2021 · 0 comments
Labels
documentation Improvements or additions to documentation vscode

Comments

@PDKSophia
Copy link
Owner

PDKSophia commented Feb 4, 2021

场景

当你鼠标光标hover至某个代码时,你想要显示一些文字内容

代码展示

// demo6 对package.json中的author进行悬停提示
import * as vscode from 'vscode'

module.exports = function (context: vscode.ExtensionContext) {
  let disposable = vscode.languages.registerHoverProvider('json', {
    provideHover(document, position, token) {
      const fileName = document.fileName
      const word = document.getText(document.getWordRangeAtPosition(position))
      if (/\/package\.json$/.test(fileName) && /\bauthor\b/.test(word)) {
        return new vscode.Hover('悬停提示: 彭道宽牛逼!')
      }
      return undefined
    },
  })

  context.subscriptions.push(disposable)
}
// extension.ts
import * as vscode from 'vscode'
export function activate(context: vscode.ExtensionContext) {
  console.log('your extension "sugar-demo-vscode" is now active!')
  require('./beehive-hoverTips')(context) // demo6 悬停提示
}
export function deactivate() {}

效果展示

image

源码展示

@PDKSophia PDKSophia added documentation Improvements or additions to documentation vscode labels Feb 4, 2021
@PDKSophia PDKSophia changed the title 06. 悬停提示-例子 06. 悬停提示—例子 Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation vscode
Projects
None yet
Development

No branches or pull requests

1 participant