commit 97fd2011542f64bb2571bf9ca0526c686307264f Author: yutent Date: Wed Feb 16 19:20:15 2022 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e347624 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +.DS_Store +.AppleDouble +.LSOverride + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes +package-lock.json + +node_modules +.vscode-test +out.js +demo.js +*.vsix +*.css \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8380796 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: node_js + +os: + - osx + +node_js: + - node + +install: + - npm install + +cache: + directories: + - "node_modules" + +script: + - npm test + +notifications: + email: false \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6899e23 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +// A launch configuration that launches the extension inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ] + }, + { + "name": "Extension Tests", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--extensionTestsPath=${workspaceFolder}/test/suite/index" + ] + } + ] +} diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..1bd2951 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,10 @@ +.vscode/** +.vscode-test/** +node_modules/** +test/** +package-lock.json +.travis.yml +.gitignore +index.js +test.js + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6fe0812 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# 更新日志(Changed Logs) + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ab60297 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3379ffe --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# auto-path +> 自动提示文件路径, 方便引入项目为的文件. + +[![Version](https://vsmarketplacebadge.apphb.com/version-short/yutent.auto-path.svg)](https://marketplace.visualstudio.com/items?itemName=yutent.auto-path) +[![Rating](https://vsmarketplacebadge.apphb.com/rating-short/yutent.auto-path.svg)](https://marketplace.visualstudio.com/items?itemName=yutent.auto-path) +[![Installs](https://vsmarketplacebadge.apphb.com/installs/yutent.auto-path.svg)](https://marketplace.visualstudio.com/items?itemName=yutent.auto-path) +[![Build Status](https://travis-ci.org/yutent/auto-path.svg?branch=master)](https://travis-ci.org/yutent/auto-path) + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..02385bc --- /dev/null +++ b/index.js @@ -0,0 +1,115 @@ +/** + * + * @author yutent + * @date 2018/11/01 09:37:55 + */ + +const vsc = require('vscode') +const { resolve, dirname, join } = require('path') +const fs = require('fs') + +const FILE = vsc.CompletionItemKind.File +const FOLDER = vsc.CompletionItemKind.Folder + +/** + * [isdir 判断目标是否为目录] + */ +function isdir(path) { + try { + return fs.statSync(path).isDirectory() + } catch (err) { + return false + } +} + +function isfile(path) { + try { + return fs.statSync(path).isFile() + } catch (err) { + return false + } +} + +/** + * 列出目录 + */ +function ls(dir) { + try { + var list = fs.readdirSync(dir) + return list.map(it => resolve(dir, it)) + } catch (err) { + console.log(err) + return [] + } +} + +let options = { + isMiniApp: false, // 是否小程序 + configFile: '' // 配置文件路径 +} + +class AutoPath { + provideCompletionItems(doc, pos) { + var currDir = dirname(doc.fileName) + var inputTxt = doc.getText(doc.lineAt(pos).range) + var list = [] + var currDirFixed = currDir + + inputTxt = inputTxt.replace(/^['"]/, '').replace(/['"]$/, '') + currDirFixed = join(currDir, inputTxt) + + if (inputTxt.startsWith('./')) { + list.push(...ls(currDirFixed)) + } else { + currDirFixed = join(options.workspace, inputTxt) + list.push(...ls(currDirFixed)) + } + + list = list.map(k => { + let t = isdir(k) ? FOLDER : FILE + k = k.slice(currDirFixed.length) + return new vsc.CompletionItem(k, t) + }) + list.unshift(new vsc.CompletionItem('', FILE)) + + return Promise.resolve(list) + } +} + +function __init__() { + let folders = vsc.workspace.workspaceFolders + + if (folders && folders.length) { + options.workspace = folders[0].uri.path + } else { + options.workspace = '/opt/www/web/small-world/' + } + + if (options.workspace) { + try { + if (isfile(join(options.workspace, 'app.json'))) { + let conf = require(join(options.workspace, 'app.json')) + options.list = conf.pages || [] + console.log('可能是小程序', conf) + } + } catch (e) { + console.log(e) + } + } + console.log(options, folders) +} + +exports.activate = function(ctx) { + __init__() + + vsc.languages.getLanguages().then(function(data) { + // return console.log(data) + }) + let ap = new AutoPath() + let auto = vsc.languages.registerCompletionItemProvider('*', ap, '"', "'", '/') + + ctx.subscriptions.push(auto) +} + +function deactivate() {} +exports.deactivate = deactivate diff --git a/package.json b/package.json new file mode 100644 index 0000000..5ead27a --- /dev/null +++ b/package.json @@ -0,0 +1,40 @@ +{ + "name": "auth-path", + "displayName": "auth-path", + "description": "🔥 自动提示文件路径, 方便引入项目为的文件", + "version": "0.1.0", + "publisher": "yutent", + "author": "Yutent [@yutent]", + "icon": "logo.png", + "engines": { + "vscode": "^1.49.0" + }, + "categories": ["Other"], + "activationEvents": ["*"], + "main": "index.js", + "contributes": {}, + "repository": { + "type": "git", + "url": "https://github.com/yutent/auth-path.git" + }, + "keywords": [ + "autofile", + "autofilename", + "autopath", + "auto-file", + "auto-filename", + "auto-path", + "yutent" + ], + "scripts": { + "start": "esbuild index.js --bundle --outfile=out.js --external:vscode --format=cjs --platform=node", + "vscode:prepublish": "npm start -- --minify" + }, + "license": "MIT", + "dependencies": { + "iofs": "^1.1.0" + }, + "devDependencies": { + "esbuild": "^0.12.14" + } +}