diff --git a/README.md b/README.md index 95e07a9..eca316b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ - 当输入 `/`开头时, 只读取`pages`或`subPackages`中的路径。 2. vue项目 -> 判断根目录是否有 `vue.config.js`或`vite.config.js`, 有则认为是vue项目。 +> 判断根目录有 `package.json`且有使用依赖`vue`, 有则认为是vue项目。 - 当输入 `./` 开头时, 读取当前目录下的文件。 - 当输入 `@/`开头时, 只读取`src/`中的路径。 - 当输入 `/`开头时, 读取根目录的文件。 diff --git a/index.js b/index.js index ed7863a..fd72b11 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ const vsc = require('vscode') const { resolve, dirname, join } = require('path') const fs = require('fs') -const FILE = vsc.CompletionItemKind.Text +const FILE = vsc.CompletionItemKind.File const FOLDER = vsc.CompletionItemKind.Folder /** @@ -73,7 +73,7 @@ class AutoPath { return } - if (inputTxt.startsWith('./')) { + if (inputTxt.startsWith('./') || inputTxt.startsWith('../')) { list.push(...ls(currDirFixed)) } else { // 小程序 @@ -103,11 +103,14 @@ class AutoPath { } } - list = list.map(k => { - let t = options.isMiniApp ? FILE : isdir(k) ? FOLDER : FILE - k = k.slice(currDirFixed.length) - return item(k, t, pos) - }) + list = list + .filter(it => it !== doc.fileName) + .map(k => { + let t = options.isMiniApp ? FILE : isdir(k) ? FOLDER : FILE + k = k.slice(currDirFixed.length) + return item(k, t, pos) + }) + list.unshift(item('', FILE, pos)) return Promise.resolve(list) @@ -119,12 +122,8 @@ function __init__() { if (folders && folders.length) { options.workspace = folders[0].uri.path - } else { - options.workspace = '/opt/www/web/small-world' } - console.log() - if (options.workspace) { // 判断是否是小程序 if (isfile(join(options.workspace, 'app.json'))) { @@ -135,13 +134,13 @@ function __init__() { } } // 简单判断是否是vue项目 - if ( - isfile(join(options.workspace, 'vue.config.js')) || - isfile(join(options.workspace, 'vite.config.js')) - ) { - let extendWorkspace = join(options.workspace, 'src/') - if (isdir(extendWorkspace)) { - options.extendWorkspace = extendWorkspace + if (isfile(join(options.workspace, 'package.json'))) { + let conf = require(join(options.workspace, 'package.json')) + if (conf.dependencies.vue) { + let extendWorkspace = join(options.workspace, 'src/') + if (isdir(extendWorkspace)) { + options.extendWorkspace = extendWorkspace + } } } } diff --git a/package.json b/package.json index b0d1dfa..9b182b5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "auto-path", "displayName": "auto-path", "description": "🔥 自动提示文件路径, 方便引入项目为的文件", - "version": "1.0.1", + "version": "1.0.2", "publisher": "yutent", "author": "Yutent [@yutent]", "icon": "logo.png", @@ -28,7 +28,7 @@ ], "scripts": { "start": "esbuild index.js --bundle --outfile=out.js --external:vscode --format=cjs --platform=node", - "vscode:prepublish": "npm start -- --minify" + "build": "npm start -- --minify" }, "license": "MIT", "devDependencies": {