{"id":13490422,"url":"https://github.com/vscode-use/utils","last_synced_at":"2026-04-09T19:07:37.024Z","repository":{"id":172471211,"uuid":"649318417","full_name":"vscode-use/utils","owner":"vscode-use","description":"vscode lodash","archived":false,"fork":false,"pushed_at":"2024-05-19T14:22:15.000Z","size":283,"stargazers_count":95,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-19T14:38:39.985Z","etag":null,"topics":["vscode","vscode-api","vscode-use"],"latest_commit_sha":null,"homepage":"https://vscode-use-docs.netlify.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vscode-use.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Simon-He95","custom":["https://github.com/Simon-He95/sponsor"]}},"created_at":"2023-06-04T13:35:55.000Z","updated_at":"2024-05-21T10:17:04.426Z","dependencies_parsed_at":null,"dependency_job_id":"e75309a7-1f4f-4bc0-96b7-8ff9bdcda320","html_url":"https://github.com/vscode-use/utils","commit_stats":null,"previous_names":["vscode-use/utils"],"tags_count":98,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscode-use%2Futils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscode-use%2Futils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscode-use%2Futils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vscode-use%2Futils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vscode-use","download_url":"https://codeload.github.com/vscode-use/utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984423,"owners_count":20704791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vscode","vscode-api","vscode-use"],"created_at":"2024-07-31T19:00:46.449Z","updated_at":"2026-04-09T19:07:36.961Z","avatar_url":"https://github.com/vscode-use.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"./assets/kv.png\" alt=\"vscode-use/utils\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e English | \u003ca href=\"./README_zh.md\"\u003e简体中文\u003c/a\u003e\u003c/p\u003e\n\n🐰 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.\n\n## [📘 Documentation](https://vscode-use-docs.netlify.app/)\n\n## 📍 Install\n```\nnpm i @vscode-use/utils -d\n```\n\n## Recommended VSCode Starter\n- https://github.com/Simon-He95/vitesse-vscode\n\n### [Example](https://github.com/Simon-He95/vitesse-vscode)\n\n## 📝 Api\n\n- registerCommand： ***Registration instructions***\n- executeCommand： ***Trigger instructions***\n- getConfiguration： ***get workspace configuration***\n- message {type:'info'|'error',message:string,buttons:['ok']}： ***Pop up message***\n- openFile： ***Open a file.***\n- addEventListener： ***Listen to file switching, terminal, content change, add, delete and other events in vscode***\n- createTerminal： ***Quickly create a terminal***\n- createCompletionItem： ***Generate the prompt content of registerCompletionItemProvider***\n- registerCompletionItemProvider： ***Generate the corresponding prompt according to the input***\n- isDark： ***Determine whether the current vscode theme is dark***\n- getSelection： ***Get the information of the line where the current mouse is located***\n- getActiveTextEditorLanguageId： ***Get a type of the current file javascriptreact | typescriptreact | vue, etc.***\n- createProgress： ***Create an execution progress bar in vscode***\n- registerInlayHintsProvider： ***Give a hint similar to copilot.***\n- getCopyText： ***Read the pasteboard Content.***\n- setCopyText： ***Plug the content into the pasteboard.***\n- updateText： ***Modify the text content***\n- jumpToLine： ***Open a file and jump to a certain line***\n- createBottomBar： ***Create the bottom bar button***\n- nextTick： ***Create the bottom bar button***\n- createSquare： ***Create a square block***\n- watchFiles： ***Monitor changes in file content and deletion***\n- createEvents： ***Tools for subscribing to event communication***\n- getActiveText： ***Get the text content of the current activation tab***\n- fold： ***fold code***\n- unFold： ***unfold code***\n- registerDefinitionProvider： ***It provides option + click to achieve the function of fast jump.***\n- registerHoverProvider： ***Provide a callback for mouse hover***\n- registerCodeActionsProvider ***Registered Code Action Provider***\n- openExternalUrl： ***Open the external url in the browser***\n- getLineText： ***Get the text of a certain line***\n- useTheme： ***Theme Configuration and Operatation***\n- isInPosition： ***Determine whether one area is a sub-area of another***\n- getCurrentFileUrl： ***Get the path of the current activation file***\n- createInput： ***Create an input box***\n- getLocale： ***Get the local language environment***\n- rename： ***Quickly rename files***\n- createDefinitionLocation ***Create jump address data after left-clicking after pressing option***\n- setStyle ***Add style to a certain area***\n- createStyle ***Create Style***\n- getActiveTextEditor ***Get the currently activated editor***\n- getKeyWords ***Get the keywords at the position***\n- setCommandParams ***Set the click command parameter of MarkdownString***\n- getOffsetFromPosition ***Get the offset from position***\n- getRootPath ***Get the root directory path of the project***\n- registerCodeLensProvider ***Register the text button at the head of the text and tie the event.***\n- createCodeLens ***Quickly create items in provideCodeLenses***\n- saveFile ***Save the file***\n- createStyleAnimation ***Add style animation***\n- createStyleAnimations ***Add style animation group***\n- getWordRangeAtPosition ***Get the area of ​​keywords for your location***\n\n## 📖 @vscode-use/utils api description\n\n  ### The registration instruction needs to be declared in package.json. A prompt pops up in the lower right corner.\n  ```\n  registerCommand('vscode-use.hello', () =\u003e {\n    message.info('Hello World!')\n  })\n  ```\n\n  ### The registration instruction needs to be declared in package.json. An error prompt pops up in the lower right corner.\n  ```\n  registerCommand('vscode-use.error', () =\u003e {\n    message.error('Hello World!')\n  })\n  ```\n\n  ### Registration instructions need to declare in package.json to open Baidu\n  ```\n  registerCommand('vscode-use.openExternalUrl', () =\u003e {\n    openExternalUrl('http://www.baidu.com')\n  })\n  ```\n\n  ### Get the current language\n  ```\n  const isZh = getLocale().includes('zh')\n  message.info(`当前语言：${isZh ? '中文' : '英文'}`)\n  ```\n\n  ### Monitor and switch the active text editor\n  ```\n  addEventListener('activeText-change', (e) =\u003e {})\n  ```\n\n  ### Monitor login status changes\n  ```\n  addEventListener('auth-change', (e) =\u003e {})\n  ```\n\n  ### Monitoring configuration changes (including: plug-in configuration, user configuration, workspace configuration)\n  ```\n  addEventListener('config-change', (e) =\u003e {})\n  ```\n\n  ### Monitor editor visibility changes\n  ```\n  addEventListener('editor-visible', (e) =\u003e {})\n  ```\n\n  ### Monitor file creation\n  ```\n  addEventListener('file-create', (e) =\u003e {})\n  ```\n\n  ### Monitoring file deletion\n  ```\n  addEventListener('file-delete', (e) =\u003e {})\n  ```\n\n  ### Monitor folder creation and deletion\n  ```\n  addEventListener('folder-change', (e) =\u003e {})\n  ```\n\n  ### Listen to file renaming\n  ```\n  addEventListener('rename', (e) =\u003e {})\n  ```\n\n  ### Monitor the changes of selected content\n  ```\n  addEventListener('selection-change', (e) =\u003e {})\n  ```\n\n  ### Monitor terminal changes\n  ```\n  addEventListener('terminal-change', (e) =\u003e {})\n  ```\n\n  ### Monitoring terminal is closed\n  ```\n  addEventListener('terminal-close', (e) =\u003e {})\n  ```\n\n  ### Monitoring terminal creation\n  ```\n  addEventListener('terminal-open', (e) =\u003e {})\n  ```\n\n  ### Monitor text modifications\n  ```\n  addEventListener('text-change', (e) =\u003e {})\n  ```\n\n  ### Monitor new text\n  ```\n  addEventListener('text-open', (e) =\u003e {})\n  ```\n\n  ### Monitor text saving\n  ```\n  addEventListener('text-save', (e) =\u003e {})\n  ```\n### Monitor text visibility changes\n   ```\n   addEventListener('text-visible-change', (e) =\u003e {})\n   ```\n\n   ### Monitor theme changes\n   ```\n   addEventListener('theme-change', (e) =\u003e {})\n   ```\n\n   ### Jump to a certain line of a file\n   ```\n   jumpToLine(10, 'path/Uri')\n   ```\n\n   ### Collapse all lines between the start line and the end line\n   ```\n   onFold([\n     createRange([1, 0], [5, 0]),\n     createRange([5, 0], [10, 0])\n   ])\n   ```\n\n   ### Expand all lines between the start line and the end line\n   ```\n   unFold([\n     createRange([1, 0], [5, 0]),\n     createRange([5, 0], [10, 0])\n   ])\n   ```\n\n   ### Update text\n   ```\n   updateText(edit=\u003e{\n   //Insert text in the first line\n   edit.insert(new vscode.Position(0, 0), 'Hello World!')\n\n   // Delete the first 5 characters of the first line\n   edit.delete(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 5)))\n\n   // Replace the first 5 characters of the first line with Hello World!\n   edit.replace(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 5)), 'Hello World!')\n   })\n   ```\n\n   ### Get the currently active editor text\n   ```\n   const activeText = getActiveText()\n   ```\n\n   ### Get the text of a certain line\n   ```\n   const lineText = getLineText(0)\n   ```\n\n   ### Read config\n   ```\n   const mode1 = getConfiguration('vscode-use').get('mode')\n   const mode2 = getConfiguration('vscode-use.mode')\n   ```\n\n   ### Update config\n   ```\n   setConfiguration('vscode-use.mode', 'dev')\n   ```\n\n   ### Create terminal\n   ```\n   createTerminal('test')\n   ```\n\n   ### Create bottom bar\n   ```\n   createBottomBar({\n     position: 'left',\n     text: 'I am the bottom bar',\n     color: '#fff',\n     backgroundColor: '#000',\n   })\n   ```\n\n   ### Get the position based on offset\n   ```\n   const pos = getPosition(100)\n   ```\n\n   ### Get the content of the copy\n   ```\n   getCopyText().then(text=\u003e{})\n   ```\n\n   ### Write content to the clipboard\n   ```\n   setCopyText('Hello World!')\n   ```\n\n   ### Get the path of the currently active text\n   ```\n   const currentFileUrl = getCurrentFileUrl()\n   ```\n\n   ### Set selected content\n  ```\n   setSelection([0, 0], [0, 5])\n  ```\n\n   ### Set multiple selections\n   ```\n   setSelections([{\n     start: [0, 0],\n     end: [0, 5],\n     position: 'left' // Control cursor position\n   }, {\n     start: [1, 0],\n     end: [1, 5],\n     position: 'right'\n   }])\n   ```\n\n   ### Monitor file changes\n   ```\n   watchFiles('filepath', (e) =\u003e {})\n   ```\n\n   ### Create a progress bar\n   ```\n   createProgress({\n     title: 'Progress Bar',\n     async done(report) {\n       report({\n         message: 'Progress bar 10% completed',\n         increment: 10\n       })\n       setTimeout(() =\u003e {\n         report({\n           message: 'Progress bar completed 50',\n           increment: 50\n         })\n       })\n     }\n   })\n   ```\n\n   ### Create a selection box\n   ```\n   createSelect(['vue','react','svelte','solid']).then((res)=\u003e{})\n   ```\n\n   ### Listen to the event of hover element\n   ```\n   registerHoverProvider('vue', (e) =\u003e {})\n   ```\n\n   ### Monitor the click jump position when the option key is pressed.\n   ```\n   registerDefinitionProvider('vue', (e) =\u003e {})\n   ```\n\n   ### Get topic-related APIs\n   ```\n   const { getCurrentTheme, getAllTheme, setTheme, } = useTheme()\n   ```\n\n   ### Get the language of the currently active text\n   ```\n   const language = getActiveTextEditorLanguageId() // vue\n   ```\n\n   ### Rename file\n   ```\n   rename('url', 'newUrl')\n   ```\n\n   ### nextTick, some operations after file changes need to wait for the file to change before executing\n   ```\n    nextTick(()=\u003e{})\n   ```\n\n   ### Add style\n   ```\n   setStyle(createStyle({\n     backgroundColor: 'yellow',\n     border: '1px solid red'\n   }), createRange([0, 0], [0, 10]))\n   ```\n\n   ### Create input box\n\n   ```\n   createInput({\n     title: 'I am an input box',\n     placeHolder: 'Please enter content',\n     value: ''\n   })\n   ```\n\n  ### getActiveTextEditor\n\n  ```\n  const activeTextEditor = getActiveTextEditor()\n  ```\n\n  ### getKeyWords\n\n  ```\n  const keyWords = getKeyWords(position)\n  ```\n\n  ### Set the click command parameter of MarkdownString\n\n  ```\n  const md = new vscode.MarkdownString()\n  md.isTrusted = true\n  md.supportHtml = true\n  const commandUri = `command:a.b?${setCommandParams(['params1', 'params2'])}`\n  md.appendMarkdown(`[🦘](${commandUri})`);\n  ```\n\n  ### getOffsetFromPosition\n  ```\n  const offset = getOffsetFromPosition(position) // Get the offset of the current text and location\n  const offset = getOffsetFromPosition(position,code) // 获取指定code，位置的offset\n  ```\n\n## License\n\n[MIT](./LICENSE) License © 2022 [Simon He](https://github.com/Simon-He95)\n\n\u003ca href=\"https://github.com/Simon-He95/sponsor\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" style=\"height: 51px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n","funding_links":["https://github.com/sponsors/Simon-He95","https://github.com/Simon-He95/sponsor"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvscode-use%2Futils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvscode-use%2Futils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvscode-use%2Futils/lists"}