English | 简体中文
🐰 vscode use has a secondary encapsulation of the vscode api, providing a large number of streamlined and practical functions, and making the function names closer to the actual meaning, just like lodash in vscode.
npm i @vscode-use/utils -d
- registerCommand: Registration instructions
- executeCommand: Trigger instructions
- getConfiguration: get workspace configuration
- message {type:'info'|'error',message:string,buttons:['ok']}: Pop up message
- openFile: Open a file.
- addEventListener: Listen to file switching, terminal, content change, add, delete and other events in vscode
- createTerminal: Quickly create a terminal
- createCompletionItem: Generate the prompt content of registerCompletionItemProvider
- registerCompletionItemProvider: Generate the corresponding prompt according to the input
- isDark: Determine whether the current vscode theme is dark
- getSelection: Get the information of the line where the current mouse is located
- getActiveTextEditorLanguageId: Get a type of the current file javascriptreact | typescriptreact | vue, etc.
- createProgress: Create an execution progress bar in vscode
- registerInlayHintsProvider: Give a hint similar to copilot.
- getCopyText: Read the pasteboard Content.
- setCopyText: Plug the content into the pasteboard.
- updateText: Modify the text content
- jumpToLine: Open a file and jump to a certain line
- createBottomBar: Create the bottom bar button
- nextTick: Create the bottom bar button
- createSquare: Create a square block
- watchFiles: Monitor changes in file content and deletion
- createEvents: Tools for subscribing to event communication
- getActiveText: Get the text content of the current activation tab
- fold: fold code
- unFold: unfold code
- registerDefinitionProvider: It provides option + click to achieve the function of fast jump.
- registerHoverProvider: Provide a callback for mouse hover
- registerCodeActionsProvider Registered Code Action Provider
- openExternalUrl: Open the external url in the browser
- getLineText: Get the text of a certain line
- useTheme: Theme Configuration and Operatation
- isInPosition: Determine whether one area is a sub-area of another
- getCurrentFileUrl: Get the path of the current activation file
- createInput: Create an input box
- getLocale: Get the local language environment
- rename: Quickly rename files
- createDefinitionLocation Create jump address data after left-clicking after pressing option
- setStyle Add style to a certain area
- createStyle Create Style
- getActiveTextEditor Get the currently activated editor
- getKeyWords Get the keywords at the position
- setCommandParams Set the click command parameter of MarkdownString
- getOffsetFromPosition Get the offset from position
- getRootPath Get the root directory path of the project
- registerCodeLensProvider Register the text button at the head of the text and tie the event.
- createCodeLens Quickly create items in provideCodeLenses
- saveFile Save the file
- createStyleAnimation Add style animation
- createStyleAnimations Add style animation group
- getWordRangeAtPosition Get the area of keywords for your location
The registration instruction needs to be declared in package.json. A prompt pops up in the lower right corner.
registerCommand('vscode-use.hello', () => {
message.info('Hello World!')
})
The registration instruction needs to be declared in package.json. An error prompt pops up in the lower right corner.
registerCommand('vscode-use.error', () => {
message.error('Hello World!')
})
registerCommand('vscode-use.openExternalUrl', () => {
openExternalUrl('http://www.baidu.com')
})
const isZh = getLocale().includes('zh')
message.info(`当前语言:${isZh ? '中文' : '英文'}`)
addEventListener('activeText-change', (e) => {})
addEventListener('auth-change', (e) => {})
Monitoring configuration changes (including: plug-in configuration, user configuration, workspace configuration)
addEventListener('config-change', (e) => {})
addEventListener('editor-visible', (e) => {})
addEventListener('file-create', (e) => {})
addEventListener('file-delete', (e) => {})
addEventListener('folder-change', (e) => {})
addEventListener('rename', (e) => {})
addEventListener('selection-change', (e) => {})
addEventListener('terminal-change', (e) => {})
addEventListener('terminal-close', (e) => {})
addEventListener('terminal-open', (e) => {})
addEventListener('text-change', (e) => {})
addEventListener('text-open', (e) => {})
addEventListener('text-save', (e) => {})
addEventListener('text-visible-change', (e) => {})
addEventListener('theme-change', (e) => {})
jumpToLine(10, 'path/Uri')
onFold([
createRange([1, 0], [5, 0]),
createRange([5, 0], [10, 0])
])
unFold([
createRange([1, 0], [5, 0]),
createRange([5, 0], [10, 0])
])
updateText(edit=>{
//Insert text in the first line
edit.insert(new vscode.Position(0, 0), 'Hello World!')
// Delete the first 5 characters of the first line
edit.delete(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 5)))
// Replace the first 5 characters of the first line with Hello World!
edit.replace(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 5)), 'Hello World!')
})
const activeText = getActiveText()
const lineText = getLineText(0)
const mode1 = getConfiguration('vscode-use').get('mode')
const mode2 = getConfiguration('vscode-use.mode')
setConfiguration('vscode-use.mode', 'dev')
createTerminal('test')
createBottomBar({
position: 'left',
text: 'I am the bottom bar',
color: '#fff',
backgroundColor: '#000',
})
const pos = getPosition(100)
getCopyText().then(text=>{})
setCopyText('Hello World!')
const currentFileUrl = getCurrentFileUrl()
setSelection([0, 0], [0, 5])
setSelections([{
start: [0, 0],
end: [0, 5],
position: 'left' // Control cursor position
}, {
start: [1, 0],
end: [1, 5],
position: 'right'
}])
watchFiles('filepath', (e) => {})
createProgress({
title: 'Progress Bar',
async done(report) {
report({
message: 'Progress bar 10% completed',
increment: 10
})
setTimeout(() => {
report({
message: 'Progress bar completed 50',
increment: 50
})
})
}
})
createSelect(['vue','react','svelte','solid']).then((res)=>{})
registerHoverProvider('vue', (e) => {})
registerDefinitionProvider('vue', (e) => {})
const { getCurrentTheme, getAllTheme, setTheme, } = useTheme()
const language = getActiveTextEditorLanguageId() // vue
rename('url', 'newUrl')
nextTick(()=>{})
setStyle(createStyle({
backgroundColor: 'yellow',
border: '1px solid red'
}), createRange([0, 0], [0, 10]))
createInput({
title: 'I am an input box',
placeHolder: 'Please enter content',
value: ''
})
const activeTextEditor = getActiveTextEditor()
const keyWords = getKeyWords(position)
const md = new vscode.MarkdownString()
md.isTrusted = true
md.supportHtml = true
const commandUri = `command:a.b?${setCommandParams(['params1', 'params2'])}`
md.appendMarkdown(`[🦘](${commandUri})`);
const offset = getOffsetFromPosition(position) // Get the offset of the current text and location
const offset = getOffsetFromPosition(position,code) // 获取指定code,位置的offset