From fda19e73535957340bfe1bdd154241f21b364de0 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 18 Feb 2022 10:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=B0=83=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81;=E4=BF=AE=E5=A4=8D=E5=AF=B9../=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81;=E8=BF=87=E6=BB=A4=E6=8E=89=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9C=AC=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- index.js | 35 +++++++++++++++++------------------ package.json | 4 ++-- 3 files changed, 20 insertions(+), 21 deletions(-) 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": {