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

vs code 插件开发 #92

Open
huruji opened this issue May 5, 2020 · 0 comments
Open

vs code 插件开发 #92

huruji opened this issue May 5, 2020 · 0 comments

Comments

@huruji
Copy link
Owner

huruji commented May 5, 2020

使用案例

将选中的文本替换

选中文本转化为大写:

import * as vscode from 'vscode'

import { Range, commands } from 'vscode'

export function activate(context: vscode.ExtensionContext) {
  console.log('active')
  const disposable = commands.registerTextEditorCommand('uppercase.toUpperCase', toUpperCase)
  context.subscriptions.push(disposable)
}

function toUpperCase(editor: vscode.TextEditor) {
  editor.edit(builder => {
    editor.selections.forEach(selection => {
      const range = new Range(selection.start, selection.end)
      const text = editor.document.getText(range) || ''
      builder.replace(selection, text.toLocaleUpperCase())
    })
  })
}

export function deactivate() {
  return
}

参考:https://github.com/ruiquelhas/vscode-uppercase

选中 hover 效果

export function activate(context: vscode.ExtensionContext) {
  const hover = languages.registerHoverProvider({
    scheme: '*',
    language: '*',
  }, {
    provideHover(document, position, token) {
      return new Hover('hello world')
    }
  })

  context.subscriptions.push(hover)
}

参考:https://github.com/thegtproject/vscode-hoverhex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant