From 12e7769972bdb0c8008528c4242ccb822e012e9f Mon Sep 17 00:00:00 2001 From: William Killerud Date: Mon, 8 Aug 2022 19:08:58 +0200 Subject: [PATCH 1/6] chore: clean dist between publishes, ignore some more --- .vscodeignore | 3 +++ package.json | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.vscodeignore b/.vscodeignore index dec8c82b..d35909cb 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -9,6 +9,7 @@ npm-debug.log* # Configuration .github/ .vscode/ +.husky/ .editorconfig .eslintrc.json .gitattributes @@ -26,9 +27,11 @@ node_modules/ .nyc_output/ coverage/ fixtures/ +dist/test/ src/ types/ patches/ +CONTRIBUTING.md CHANGELOG.md # Build artifacts diff --git a/package.json b/package.json index 324fb8ab..bb4a2bd0 100644 --- a/package.json +++ b/package.json @@ -156,8 +156,9 @@ "prepare": "husky install", "lint-staged": "lint-staged", "vscode:prepublish": "npm run build", - "build": "webpack --mode production --devtool hidden-source-map", - "dev": "webpack --mode development --watch", + "clean": "rimraf dist", + "build": "npm run clean && webpack --mode production --devtool hidden-source-map", + "dev": "npm run clean && webpack --mode development --watch", "lint": "eslint \"src/**/*.ts\" --cache", "test": "npm run test:clean && npm run test:compile && npm run test:unit", "test:clean": "rimraf out", From 8e7388f3297f2c43fae0082a8007342a2d9f1c68 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Wed, 10 Aug 2022 18:18:03 +0200 Subject: [PATCH 2/6] fix: scoped module without path --- src/server/parser/document.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/parser/document.ts b/src/server/parser/document.ts index 380ff2a0..5a50ccb2 100644 --- a/src/server/parser/document.ts +++ b/src/server/parser/document.ts @@ -12,7 +12,12 @@ import type { NodeFileSystem } from "../../shared/node-file-system"; function getModuleNameFromPath(path: string) { // If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first isntance of '/' if (path.startsWith("@")) { - return path.slice(0, Math.max(0, path.indexOf("/", path.indexOf("/") + 1))); + const secondSlash = path.indexOf("/", path.indexOf("/") + 1); + // If there's no second slash (a use from the root of the scoped module) return the path as-is + if (secondSlash === -1) { + return path; + } + return path.slice(0, secondSlash); } return path.slice(0, Math.max(0, path.indexOf("/"))); From cee78c752d2fecdab8899fe718ea556a845da025 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Wed, 10 Aug 2022 18:27:45 +0200 Subject: [PATCH 3/6] refactor: apparently we can do this and still have things work? The language server handles most if not all of that stuff anyway. No sense duplicating the effort. --- src/server/parser/document.ts | 82 ++--------------------------------- src/server/parser/parser.ts | 2 +- 2 files changed, 4 insertions(+), 80 deletions(-) diff --git a/src/server/parser/document.ts b/src/server/parser/document.ts index 5a50ccb2..863c8d92 100644 --- a/src/server/parser/document.ts +++ b/src/server/parser/document.ts @@ -1,68 +1,10 @@ -import { dirname, join } from "path"; import type { DocumentContext } from "vscode-css-languageservice"; -import { URI } from "vscode-uri"; +import { URI, Utils } from "vscode-uri"; import { FileSystemProvider } from "../../shared/file-system"; -import type { NodeFileSystem } from "../../shared/node-file-system"; - -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - * See https://github.com/microsoft/vscode/blob/main/LICENSE.txt for license information. - *--------------------------------------------------------------------------------------------*/ -function getModuleNameFromPath(path: string) { - // If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first isntance of '/' - if (path.startsWith("@")) { - const secondSlash = path.indexOf("/", path.indexOf("/") + 1); - // If there's no second slash (a use from the root of the scoped module) return the path as-is - if (secondSlash === -1) { - return path; - } - return path.slice(0, secondSlash); - } - - return path.slice(0, Math.max(0, path.indexOf("/"))); -} - -function resolvePathToModule( - moduleName: string, - relativeTo: string, - fs: FileSystemProvider, -): string | undefined { - // Resolve the module relative to the document. We can't use `require` here as the code is webpacked. - // fsPath use is OK here since we never reach this function unless the URI is a file://. - const documentFolder = dirname(URI.parse(relativeTo).fsPath); - - // Assume this path exists. If not, let VS Code deal with the "404" and have the user fix a typo or install node_modules. - const packPath = join( - documentFolder, - "node_modules", - moduleName, - "package.json", - ); - - if (Object.prototype.hasOwnProperty.call(fs, "existsSync")) { - if ((fs as NodeFileSystem).existsSync(packPath)) { - return URI.file(packPath).toString(); - } - } - - return undefined; -} - -function resolve(from: string, to: string): string { - const resolvedUrl = new URL(to, new URL(from, "resolve://")); - if (resolvedUrl.protocol === "resolve:") { - // `from` is a relative URL. - const { pathname, search, hash } = resolvedUrl; - return pathname + search + hash; - } - return resolvedUrl.toString(); -} export function buildDocumentContext( documentUri: string, workspaceRoot: URI, - fs: FileSystemProvider, ): DocumentContext { function getRootFolder(): string | undefined { let folderURI = workspaceRoot.toString(); @@ -88,26 +30,8 @@ export function buildDocumentContext( return folderUri + ref.slice(1); } } - - // Following [css-loader](https://github.com/webpack-contrib/css-loader#url) - // and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports) - // convention, if an import path starts with ~ then use node module resolution - // *unless* it starts with "~/" as this refers to the user's home directory. - if (ref.startsWith("~") && ref[1] !== "/") { - ref = ref.slice(1); - if (base.startsWith("file://")) { - const moduleName = getModuleNameFromPath(ref); - const modulePath = resolvePathToModule(moduleName, base, fs); - if (modulePath) { - const pathWithinModule = ref.slice( - Math.max(0, moduleName.length + 1), - ); - return resolve(modulePath, pathWithinModule); - } - } - } - - return resolve(base, ref); + base = base.substr(0, base.lastIndexOf("/") + 1); + return Utils.resolvePath(URI.parse(base), ref).toString(); }, }; } diff --git a/src/server/parser/parser.ts b/src/server/parser/parser.ts index 6c83b812..6ebad3dc 100644 --- a/src/server/parser/parser.ts +++ b/src/server/parser/parser.ts @@ -57,7 +57,7 @@ async function findDocumentSymbols( const links = await ls.findDocumentLinks2( document, ast, - buildDocumentContext(document.uri, workspaceRoot, fs), + buildDocumentContext(document.uri, workspaceRoot), ); const text = document.getText(); From 1ab67c1935cbbebcedea65878f70453359cd0e09 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Wed, 10 Aug 2022 18:52:41 +0200 Subject: [PATCH 4/6] fix: support imports from the root level of scoped packages --- .../vscode-css-languageservice+6.0.1.patch | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 patches/vscode-css-languageservice+6.0.1.patch diff --git a/patches/vscode-css-languageservice+6.0.1.patch b/patches/vscode-css-languageservice+6.0.1.patch new file mode 100644 index 00000000..4cc74a86 --- /dev/null +++ b/patches/vscode-css-languageservice+6.0.1.patch @@ -0,0 +1,45 @@ +diff --git a/node_modules/vscode-css-languageservice/lib/esm/services/cssNavigation.js b/node_modules/vscode-css-languageservice/lib/esm/services/cssNavigation.js +index 63b64d7..be64b1d 100644 +--- a/node_modules/vscode-css-languageservice/lib/esm/services/cssNavigation.js ++++ b/node_modules/vscode-css-languageservice/lib/esm/services/cssNavigation.js +@@ -370,9 +370,14 @@ function toTwoDigitHex(n) { + return r.length !== 2 ? '0' + r : r; + } + function getModuleNameFromPath(path) { +- // If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first instance of '/' ++ // If a scoped module (starts with @) then get up until second instance of '/', or to the end of the string for root-level imports. + if (path[0] === '@') { +- return path.substring(0, path.indexOf('/', path.indexOf('/') + 1)); ++ const secondSlash = path.indexOf('/', path.indexOf('/') + 1); ++ if (secondSlash === -1) { ++ return path; ++ } ++ return path.substring(0, path.indexOf('/', path.indexOf('/') + 1)); + } +- return path.substring(0, path.indexOf('/')); ++ // Otherwise get until first instance of '/' ++ return path.substring(0, path.indexOf('/')); + } +diff --git a/node_modules/vscode-css-languageservice/lib/umd/services/cssNavigation.js b/node_modules/vscode-css-languageservice/lib/umd/services/cssNavigation.js +index 3a42b53..d6725fd 100644 +--- a/node_modules/vscode-css-languageservice/lib/umd/services/cssNavigation.js ++++ b/node_modules/vscode-css-languageservice/lib/umd/services/cssNavigation.js +@@ -382,10 +382,15 @@ + return r.length !== 2 ? '0' + r : r; + } + function getModuleNameFromPath(path) { +- // If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first instance of '/' ++ // If a scoped module (starts with @) then get up until second instance of '/', or to the end of the string for root-level imports. + if (path[0] === '@') { +- return path.substring(0, path.indexOf('/', path.indexOf('/') + 1)); ++ const secondSlash = path.indexOf('/', path.indexOf('/') + 1); ++ if (secondSlash === -1) { ++ return path; ++ } ++ return path.substring(0, path.indexOf('/', path.indexOf('/') + 1)); + } +- return path.substring(0, path.indexOf('/')); ++ // Otherwise get until first instance of '/' ++ return path.substring(0, path.indexOf('/')); + } + }); From ff114f6ad8badc1b2498e9ddc235298cedde13a2 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Wed, 10 Aug 2022 19:28:55 +0200 Subject: [PATCH 5/6] chore: remove unused import --- src/server/parser/document.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/parser/document.ts b/src/server/parser/document.ts index 863c8d92..9a02ec84 100644 --- a/src/server/parser/document.ts +++ b/src/server/parser/document.ts @@ -1,6 +1,5 @@ import type { DocumentContext } from "vscode-css-languageservice"; import { URI, Utils } from "vscode-uri"; -import { FileSystemProvider } from "../../shared/file-system"; export function buildDocumentContext( documentUri: string, From eb4a8da914e4e540e6c4b4c9757330af70323fd4 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Wed, 10 Aug 2022 19:29:07 +0200 Subject: [PATCH 6/6] release: bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb4a2bd0..b00bea98 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "some-sass", "displayName": "Some Sass", "description": "Provides code suggestions, documentation and code navigation for modern SCSS", - "version": "2.6.0", + "version": "2.6.1", "publisher": "SomewhatStationery", "license": "MIT", "engines": {