diff --git a/README.md b/README.md index f1328f4..8f32f68 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,2 @@ -# zsh README - -This is the README for your extension "zsh". After writing up a brief description, we recommend including the following sections. - -## Features - -Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file. - -For example if there is an image subfolder under your extension project workspace: - -\!\[feature X\]\(images/feature-x.png\) - -> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow. - -## Requirements - -If you have any requirements or dependencies, add a section describing those and how to install and configure them. - -## Extension Settings - -Include if your extension adds any VS Code settings through the `contributes.configuration` extension point. - -For example: - -This extension contributes the following settings: - -* `myExtension.enable`: enable/disable this extension -* `myExtension.thing`: set to `blah` to do something - -## Known Issues - -Calling out known issues can help limit users opening duplicate issues against your extension. - -## Release Notes - -Users appreciate release notes as you update your extension. - -### 1.0.0 - -Initial release of ... - -### 1.0.1 - -Fixed issue #. - -### 1.1.0 - -Added features X, Y, and Z. - ------------------------------------------------------------------------------------------------------------ - -## Working with Markdown - -**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: - -* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux) -* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux) -* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets - -### For more information - -* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) -* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) - -**Enjoy!** +# zsh completion script +detect first line of file, if match `#compdef` or `#autoload`, mark it as `shellscript` \ No newline at end of file diff --git a/extension.js b/extension.js index 6d831fa..026005b 100644 --- a/extension.js +++ b/extension.js @@ -1,35 +1,29 @@ -// The module 'vscode' contains the VS Code extensibility API -// Import the module and reference it with the alias vscode in your code below const vscode = require('vscode'); -// this method is called when your extension is activated -// your extension is activated the very first time the command is executed - -/** - * @param {vscode.ExtensionContext} context - */ -function activate(context) { - - // Use the console to output diagnostic information (console.log) and errors (console.error) - // This line of code will only be executed once when your extension is activated - console.log('Congratulations, your extension "zsh" is now active!'); - - // The command has been defined in the package.json file - // Now provide the implementation of the command with registerCommand - // The commandId parameter must match the command field in package.json - let disposable = vscode.commands.registerCommand('zsh.helloWorld', function () { - // The code you place here will be executed every time your command is executed - - // Display a message box to the user - vscode.window.showInformationMessage('Hello World from zsh!'); - }); +function detect() { + if (vscode.window.activeTextEditor.document.languageId != 'plaintext') { + return + } + const line = vscode.window.activeTextEditor.document.lineAt(0).text + if (line && line.match(/^#compdef|^#autoload/)) { + vscode.languages + .setTextDocumentLanguage(vscode.window.activeTextEditor.document, "shellscript") + .catch(err => { + console.error(err) + }) + } +} - context.subscriptions.push(disposable); +function activate() { + vscode.window.onDidChangeVisibleTextEditors(() => { + detect() + }) + detect() } + exports.activate = activate; -// this method is called when your extension is deactivated -function deactivate() {} +function deactivate() { } module.exports = { activate, diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..f1f3526 Binary files /dev/null and b/icon.png differ diff --git a/package.json b/package.json index 2fd8bc1..6dc735f 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,20 @@ { - "name": "zsh", - "displayName": "zsh", - "description": "", - "version": "0.0.1", + "name": "zsh-completion-script", + "displayName": "zsh completion script detect", + "description": "zsh completion script detect", + "version": "1.0.0", + "publisher": "dual", + "icon": "icon.png", "engines": { "vscode": "^1.43.0" }, "categories": [ - "Other" + "Programming Languages" ], "activationEvents": [ - "onCommand:zsh.helloWorld" + "onLanguage:plaintext" ], "main": "./extension.js", - "contributes": { - "commands": [ - { - "command": "zsh.helloWorld", - "title": "Hello World" - } - ] - }, "scripts": { "lint": "eslint .", "pretest": "npm run lint", @@ -37,4 +31,4 @@ "typescript": "^3.8.3", "vscode-test": "^1.3.0" } -} +} \ No newline at end of file