From f7cc83283f677174533d1a24e7fb61dc779fb4eb Mon Sep 17 00:00:00 2001 From: jwilliams720 Date: Thu, 1 Dec 2022 11:50:17 +0000 Subject: [PATCH 1/3] Updates --- CHANGELOG.md | 135 ++++++++++++------- package-lock.json | 174 +++++++++++++------------ package.json | 4 +- src/_language-service.ts | 207 ++++++++++++++---------------- src/_logger.ts | 7 +- src/_plugin.ts | 19 ++- src/_virtual-document-provider.ts | 11 +- src/index.ts | 3 +- 8 files changed, 297 insertions(+), 263 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a887e22..8c61230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,122 +1,163 @@ # Changelog +## 0.20.0 - December 01, 2022 + +- Forked into @styled + ## 0.18.2 - December 06, 2021 -- Include completion spans in responses. Thanks @jasonwilliams! -- Don't trigger completions when opening template tags. Thanks @jasonwilliams! + +- Include completion spans in responses. Thanks @jasonwilliams! +- Don't trigger completions when opening template tags. Thanks @jasonwilliams! ## 0.18.1 - August 05, 2021 -- Update emmet. Thanks @jasonwilliams! + +- Update emmet. Thanks @jasonwilliams! ## 0.18.0 - June 03, 2021 -- Enable IntelliSense in `keyframes`. Thanks @jasonwilliams! + +- Enable IntelliSense in `keyframes`. Thanks @jasonwilliams! ## 0.17.0 - May 07, 2021 -- Apply in `keyframes` by default. Thanks @jasonwilliams! + +- Apply in `keyframes` by default. Thanks @jasonwilliams! ## 0.16.0 - April 28, 2021 -- Pick up new language service version. Thanks @hantatsang and @jasonwilliams! + +- Pick up new language service version. Thanks @hantatsang and @jasonwilliams! ## 0.15.0 - October 16, 2019 -- Pick up new language service version. Thanks @apust! + +- Pick up new language service version. Thanks @apust! ## 0.14.0 - February 26, 2019 -- Pick up new language service version. -- Support for dynamically changing configuration. -- Only enable plugin for TS 3.0+ in order to support automatically enabling plugin for workspace TS versions. + +- Pick up new language service version. +- Support for dynamically changing configuration. +- Only enable plugin for TS 3.0+ in order to support automatically enabling plugin for workspace TS versions. ## 0.13.0 - November 8, 2018 -- Mark color completions with the `'color'` `kindModifier`. This allows editors to render the color previews inline. -- Fix more false positive errors. + +- Mark color completions with the `'color'` `kindModifier`. This allows editors to render the color previews inline. +- Fix more false positive errors. ## 0.12.0 - October 15, 2018 -- Pick up new decorator library version to fix a possible state corruption error. + +- Pick up new decorator library version to fix a possible state corruption error. ## 0.11.0 - September 11, 2018 -- Fixed some false positive errors when using a placeholder in a contexual selector. Thanks @lukyth! -- Apply in `injectGlobal` or `createGlobalStyle` by default. Thanks @scf4! + +- Fixed some false positive errors when using a placeholder in a contexual selector. Thanks @lukyth! +- Apply in `injectGlobal` or `createGlobalStyle` by default. Thanks @scf4! ## 0.10.0 - July 10, 2018 -- Add folding support. + +- Add folding support. ## 0.9.2 - July 9, 2018 -- Remove TS as peerDep. + +- Remove TS as peerDep. ## 0.9.1 - July 9, 2018 -- Allow language service to be consumed by other libraries. + +- Allow language service to be consumed by other libraries. ## 0.8.1 - July 2, 2018 -- Fix some false error reports around creative uses of placeholders. + +- Fix some false error reports around creative uses of placeholders. ## 0.8.0 - July 2, 2018 -- Support for emotion style typescript declarations. + +- Support for emotion style typescript declarations. ## 0.7.0 - June 25, 2018 -- Picked up new CSS version. Brings improved suggestions and better documentation. + +- Picked up new CSS version. Brings improved suggestions and better documentation. ## 0.6.3 - April 20, 2018 -- Fixed `width: ${1}%;` incorrectly reported as an error. + +- Fixed `width: ${1}%;` incorrectly reported as an error. ## 0.6.2 - April 18, 2018 -- Fixed case where a placeholder that looked like a mixin was incorrectly reported as an error. + +- Fixed case where a placeholder that looked like a mixin was incorrectly reported as an error. ## 0.6.1 - April 16, 2018 -- Fixed some cases where placeholder usage was incorrectly reported as an error. + +- Fixed some cases where placeholder usage was incorrectly reported as an error. ## 0.6.0 - February 16, 2018 -- Added emmet suggestions. Thanks @ramya-rao-a! + +- Added emmet suggestions. Thanks @ramya-rao-a! ## 0.5.1 - February 13, 2018 -- Small fix for suggestions inside of nested selectors. + +- Small fix for suggestions inside of nested selectors. ## 0.5.0 - February 12, 2018 -- Add quick fixes for misspelled property names. + +- Add quick fixes for misspelled property names. ## 0.4.1 - February 12, 2018 -- Fixed false error when placeholder is used as a selector. + +- Fixed false error when placeholder is used as a selector. ## 0.4.0 - January 16, 2018 -- Fix suggestions inside of nested selectors. Thanks @aczekajski! + +- Fix suggestions inside of nested selectors. Thanks @aczekajski! ## 0.3.1 - January 11, 2018 -- Cache completion entries so we don't recompute them as often. + +- Cache completion entries so we don't recompute them as often. ## 0.3.0 - January 9, 2018 -- Added basic support for completion entry details + +- Added basic support for completion entry details ## 0.2.2 - November 29, 2017 -- Fix auto import completions not showing up when using plugin with TS 2.6.2+ + +- Fix auto import completions not showing up when using plugin with TS 2.6.2+ ## 0.2.1 - November 27, 2017 -- Fix cases where placeholder is followed by a trailing semicolon. Thanks @kingdaro! + +- Fix cases where placeholder is followed by a trailing semicolon. Thanks @kingdaro! ## 0.2.0 - November 9, 2017 -- Do not take runtime dependecy on TypeScript. + +- Do not take runtime dependecy on TypeScript. ## 0.1.2 — October 24, 2017 -- Fix bug that could cause errors not to be reported when on the last line of a block. + +- Fix bug that could cause errors not to be reported when on the last line of a block. ## 0.1.1 — October 24, 2017 -- Compile to ES5 to support regular Visual Studio + +- Compile to ES5 to support regular Visual Studio ## 0.1.0 -- Support for nested classes. Thanks @asvetliakov! -- Support for styled properties, such as `MyButton.extend...`. Thanks @asvetliakov! -- Fix a bug that could cause errors to stop being reported. + +- Support for nested classes. Thanks @asvetliakov! +- Support for styled properties, such as `MyButton.extend...`. Thanks @asvetliakov! +- Fix a bug that could cause errors to stop being reported. ### 0.0.5 - September 29, 2017 -- Fix empty value error being showing when using placeholder for value in multiline template strings. + +- Fix empty value error being showing when using placeholder for value in multiline template strings. ### 0.0.4 - September 29, 2017 -- Fix multiline strings with placeholders. + +- Fix multiline strings with placeholders. ### 0.0.3 - September 29, 2017 -- Initial support for strings with placeholders. + +- Initial support for strings with placeholders. ### 0.0.2 - September 29, 2017 -- Disable empty ruleset lint error by default -- Fix styled completions showing on character immediately before start of string -- Supprt `css` tag by default. -- Remove a bunch of files from published npm package. + +- Disable empty ruleset lint error by default +- Fix styled completions showing on character immediately before start of string +- Supprt `css` tag by default. +- Remove a bunch of files from published npm package. ### 0.0.1 - September 28, 2017 -- Initial release \ No newline at end of file + +- Initial release diff --git a/package-lock.json b/package-lock.json index d97f707..78ab4a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,9 @@ "version": "0.19.0", "license": "MIT", "dependencies": { + "@vscode/emmet-helper": "^2.8.4", "typescript-template-language-service-decorator": "^2.3.1", "vscode-css-languageservice": "^6.2.1", - "vscode-emmet-helper": "^2.6.4", "vscode-languageserver-textdocument": "^1.0.7", "vscode-languageserver-types": "^3.17.2" }, @@ -198,6 +198,21 @@ } } }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, "node_modules/@typescript-eslint/experimental-utils": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.6.0.tgz", @@ -318,6 +333,21 @@ "node": ">=0.10.0" } }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, "node_modules/@typescript-eslint/visitor-keys": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.6.0.tgz", @@ -335,6 +365,24 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@vscode/emmet-helper": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/@vscode/emmet-helper/-/emmet-helper-2.8.4.tgz", + "integrity": "sha512-lUki5QLS47bz/U8IlG9VQ+1lfxMtxMZENmU5nu4Z71eOD5j9FK0SmYGL5NiVJg9WBWeAU0VxRADMY2Qpq7BfVg==", + "dependencies": { + "emmet": "^2.3.0", + "jsonc-parser": "^2.3.0", + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-languageserver-types": "^3.15.1", + "vscode-nls": "^5.0.0", + "vscode-uri": "^2.1.2" + } + }, + "node_modules/@vscode/emmet-helper/node_modules/vscode-uri": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", + "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==" + }, "node_modules/@vscode/l10n": { "version": "0.0.10", "resolved": "https://registry.npmjs.org/@vscode/l10n/-/l10n-0.0.10.tgz", @@ -1183,20 +1231,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", @@ -2164,21 +2198,6 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, - "node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -2250,25 +2269,6 @@ "vscode-uri": "^3.0.6" } }, - "node_modules/vscode-emmet-helper": { - "version": "2.6.4", - "resolved": "https://registry.npmjs.org/vscode-emmet-helper/-/vscode-emmet-helper-2.6.4.tgz", - "integrity": "sha512-fP0nunW1RUWEKGf4gqiYLOVNFFGXSRHjCl0pikxtwCFlty8WwimM+RBJ5o0aIiwerrYD30HqeaVyvDW027Sseg==", - "deprecated": "This package has been renamed to @vscode/emmet-helper, please update to the new name", - "dependencies": { - "emmet": "^2.3.0", - "jsonc-parser": "^2.3.0", - "vscode-languageserver-textdocument": "^1.0.1", - "vscode-languageserver-types": "^3.15.1", - "vscode-nls": "^5.0.0", - "vscode-uri": "^2.1.2" - } - }, - "node_modules/vscode-emmet-helper/node_modules/vscode-uri": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", - "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==" - }, "node_modules/vscode-languageserver-textdocument": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.7.tgz", @@ -2608,6 +2608,17 @@ "regexpp": "^3.2.0", "semver": "^7.3.5", "tsutils": "^3.21.0" + }, + "dependencies": { + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + } } }, "@typescript-eslint/experimental-utils": { @@ -2675,6 +2686,15 @@ "requires": { "is-extglob": "^2.1.1" } + }, + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } } } }, @@ -2688,6 +2708,26 @@ "eslint-visitor-keys": "^3.0.0" } }, + "@vscode/emmet-helper": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/@vscode/emmet-helper/-/emmet-helper-2.8.4.tgz", + "integrity": "sha512-lUki5QLS47bz/U8IlG9VQ+1lfxMtxMZENmU5nu4Z71eOD5j9FK0SmYGL5NiVJg9WBWeAU0VxRADMY2Qpq7BfVg==", + "requires": { + "emmet": "^2.3.0", + "jsonc-parser": "^2.3.0", + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-languageserver-types": "^3.15.1", + "vscode-nls": "^5.0.0", + "vscode-uri": "^2.1.2" + }, + "dependencies": { + "vscode-uri": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", + "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==" + } + } + }, "@vscode/l10n": { "version": "0.0.10", "resolved": "https://registry.npmjs.org/@vscode/l10n/-/l10n-0.0.10.tgz", @@ -3329,13 +3369,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", @@ -4015,15 +4048,6 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, - "tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -4076,26 +4100,6 @@ "vscode-uri": "^3.0.6" } }, - "vscode-emmet-helper": { - "version": "2.6.4", - "resolved": "https://registry.npmjs.org/vscode-emmet-helper/-/vscode-emmet-helper-2.6.4.tgz", - "integrity": "sha512-fP0nunW1RUWEKGf4gqiYLOVNFFGXSRHjCl0pikxtwCFlty8WwimM+RBJ5o0aIiwerrYD30HqeaVyvDW027Sseg==", - "requires": { - "emmet": "^2.3.0", - "jsonc-parser": "^2.3.0", - "vscode-languageserver-textdocument": "^1.0.1", - "vscode-languageserver-types": "^3.15.1", - "vscode-nls": "^5.0.0", - "vscode-uri": "^2.1.2" - }, - "dependencies": { - "vscode-uri": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-2.1.2.tgz", - "integrity": "sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==" - } - } - }, "vscode-languageserver-textdocument": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.7.tgz", diff --git a/package.json b/package.json index 252950e..e5729b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@styled/typescript-styled-plugin", - "version": "0.19.0", + "version": "0.20.0", "description": "TypeScript language service plugin that adds IntelliSense for styled components", "keywords": [ "TypeScript", @@ -20,9 +20,9 @@ "url": "https://github.com/styled-components/typescript-styled-plugin/issues" }, "dependencies": { + "@vscode/emmet-helper": "^2.8.4", "typescript-template-language-service-decorator": "^2.3.1", "vscode-css-languageservice": "^6.2.1", - "vscode-emmet-helper": "^2.6.4", "vscode-languageserver-textdocument": "^1.0.7", "vscode-languageserver-types": "^3.17.2" }, diff --git a/src/_language-service.ts b/src/_language-service.ts index 2cf9d44..331be14 100644 --- a/src/_language-service.ts +++ b/src/_language-service.ts @@ -5,35 +5,30 @@ import { Logger, TemplateContext, TemplateLanguageService } from 'typescript-template-language-service-decorator'; import * as ts from 'typescript/lib/tsserverlibrary'; -import { getCSSLanguageService, getSCSSLanguageService, LanguageService, FoldingRange } from 'vscode-css-languageservice'; -import { doComplete as emmetDoComplete } from 'vscode-emmet-helper'; +import { + getCSSLanguageService, + getSCSSLanguageService, + LanguageService, + FoldingRange, +} from 'vscode-css-languageservice'; +import { doComplete as emmetDoComplete } from '@vscode/emmet-helper'; import * as vscode from 'vscode-languageserver-types'; import * as config from './_config'; import { ConfigurationManager } from './_configuration'; import { VirtualDocumentProvider } from './_virtual-document-provider'; import { TextDocument } from 'vscode-languageserver-textdocument'; - const cssErrorCode = 9999; -function arePositionsEqual( - left: ts.LineAndCharacter, - right: ts.LineAndCharacter -): boolean { +function arePositionsEqual(left: ts.LineAndCharacter, right: ts.LineAndCharacter): boolean { return left.line === right.line && left.character === right.character; } -function isAfter( - left: vscode.Position, - right: vscode.Position -): boolean { +function isAfter(left: vscode.Position, right: vscode.Position): boolean { return right.line > left.line || (right.line === left.line && right.character >= left.character); } -function overlaps( - a: vscode.Range, - b: vscode.Range -): boolean { +function overlaps(a: vscode.Range, b: vscode.Range): boolean { return !isAfter(a.end, b.start) && !isAfter(b.end, a.start); } @@ -48,14 +43,13 @@ class CompletionsCache { private _cachedCompletionsContent?: string; private _completions?: vscode.CompletionList; - public getCached( - context: TemplateContext, - position: ts.LineAndCharacter - ): vscode.CompletionList | undefined { - if (this._completions - && context.fileName === this._cachedCompletionsFile - && this._cachedCompletionsPosition && arePositionsEqual(position, this._cachedCompletionsPosition) - && context.text === this._cachedCompletionsContent + public getCached(context: TemplateContext, position: ts.LineAndCharacter): vscode.CompletionList | undefined { + if ( + this._completions && + context.fileName === this._cachedCompletionsFile && + this._cachedCompletionsPosition && + arePositionsEqual(position, this._cachedCompletionsPosition) && + context.text === this._cachedCompletionsContent ) { return this._completions; } @@ -63,11 +57,7 @@ class CompletionsCache { return undefined; } - public updateCached( - context: TemplateContext, - position: ts.LineAndCharacter, - completions: vscode.CompletionList - ) { + public updateCached(context: TemplateContext, position: ts.LineAndCharacter, completions: vscode.CompletionList) { this._cachedCompletionsFile = context.fileName; this._cachedCompletionsPosition = position; this._cachedCompletionsContent = context.text; @@ -127,7 +117,7 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { position: ts.LineAndCharacter, name: string ): ts.CompletionEntryDetails { - const item = this.getCompletionItems(context, position).items.find(x => x.label === name); + const item = this.getCompletionItems(context, position).items.find((x) => x.label === name); if (!item) { return { name, @@ -141,29 +131,29 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { return translateCompletionItemsToCompletionEntryDetails(this.typescript, item); } - public getQuickInfoAtPosition( - context: TemplateContext, - position: ts.LineAndCharacter - ): ts.QuickInfo | undefined { + public getQuickInfoAtPosition(context: TemplateContext, position: ts.LineAndCharacter): ts.QuickInfo | undefined { const doc = this.virtualDocumentFactory.createVirtualDocument(context); const stylesheet = this.scssLanguageService.parseStylesheet(doc); - const hover = this.scssLanguageService.doHover(doc, this.virtualDocumentFactory.toVirtualDocPosition(position), stylesheet); + const hover = this.scssLanguageService.doHover( + doc, + this.virtualDocumentFactory.toVirtualDocPosition(position), + stylesheet + ); if (hover) { return this.translateHover(hover, this.virtualDocumentFactory.toVirtualDocPosition(position), context); } return undefined; } - public getSemanticDiagnostics( - context: TemplateContext - ): ts.Diagnostic[] { + public getSemanticDiagnostics(context: TemplateContext): ts.Diagnostic[] { const doc = this.virtualDocumentFactory.createVirtualDocument(context); const stylesheet = this.scssLanguageService.parseStylesheet(doc); return this.translateDiagnostics( this.scssLanguageService.doValidation(doc, stylesheet), doc, context, - context.text).filter(x => !!x) as ts.Diagnostic[]; + context.text + ).filter((x) => !!x) as ts.Diagnostic[]; } public getSupportedCodeFixes(): number[] { @@ -173,28 +163,28 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { public getCodeFixesAtPosition( context: TemplateContext, start: number, - end: number, + end: number // _errorCodes: number[], // _format: ts.FormatCodeSettings ): ts.CodeAction[] { const doc = this.virtualDocumentFactory.createVirtualDocument(context); const stylesheet = this.scssLanguageService.parseStylesheet(doc); const range = this.toVsRange(context, start, end); - const diagnostics = this.scssLanguageService.doValidation(doc, stylesheet) - .filter(diagnostic => overlaps(diagnostic.range, range)); + const diagnostics = this.scssLanguageService + .doValidation(doc, stylesheet) + .filter((diagnostic) => overlaps(diagnostic.range, range)); return this.translateCodeActions( context, - this.scssLanguageService.doCodeActions(doc, range, { diagnostics }, stylesheet)); + this.scssLanguageService.doCodeActions(doc, range, { diagnostics }, stylesheet) + ); } - public getOutliningSpans( - context: TemplateContext - ): ts.OutliningSpan[] { + public getOutliningSpans(context: TemplateContext): ts.OutliningSpan[] { const doc = this.virtualDocumentFactory.createVirtualDocument(context); const ranges = this.scssLanguageService.getFoldingRanges(doc); return ranges - .filter(range => { + .filter((range) => { // Filter out ranges outside on last line const end = context.toOffset({ line: range.endLine, @@ -202,24 +192,17 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { }); return end < context.text.length; }) - .map(range => this.translateOutliningSpan(context, range)); + .map((range) => this.translateOutliningSpan(context, range)); } - private toVsRange( - context: TemplateContext, - start: number, - end: number - ): vscode.Range { + private toVsRange(context: TemplateContext, start: number, end: number): vscode.Range { return { start: this.virtualDocumentFactory.toVirtualDocPosition(context.toPosition(start)), end: this.virtualDocumentFactory.toVirtualDocPosition(context.toPosition(end)), }; } - private getCompletionItems( - context: TemplateContext, - position: ts.LineAndCharacter - ): vscode.CompletionList { + private getCompletionItems(context: TemplateContext, position: ts.LineAndCharacter): vscode.CompletionList { const cached = this._completionsCache.getCached(context, position); const completions: vscode.CompletionList = { isIncomplete: false, @@ -246,9 +229,12 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { const virtualPosition = this.virtualDocumentFactory.toVirtualDocPosition(position); const stylesheet = this.scssLanguageService.parseStylesheet(doc); this.cssLanguageService.setCompletionParticipants([]); - const emmetResults = emmetDoComplete(doc, virtualPosition, 'css', this.configurationManager.config.emmet) || emptyCompletionList; - const completionsCss = this.cssLanguageService.doComplete(doc, virtualPosition, stylesheet) || emptyCompletionList; - const completionsScss = this.scssLanguageService.doComplete(doc, virtualPosition, stylesheet) || emptyCompletionList; + const emmetResults = + emmetDoComplete(doc, virtualPosition, 'css', this.configurationManager.config.emmet) || emptyCompletionList; + const completionsCss = + this.cssLanguageService.doComplete(doc, virtualPosition, stylesheet) || emptyCompletionList; + const completionsScss = + this.scssLanguageService.doComplete(doc, virtualPosition, stylesheet) || emptyCompletionList; completionsScss.items = filterScssCompletionItems(completionsScss.items); completions.items = [...completionsCss.items, ...completionsScss.items]; @@ -267,8 +253,7 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { content: string ) { const sourceFile = context.node.getSourceFile(); - return diagnostics.map(diag => - this.translateDiagnostic(diag, sourceFile, doc, context, content)); + return diagnostics.map((diag) => this.translateDiagnostic(diag, sourceFile, doc, context, content)); } private translateDiagnostic( @@ -279,15 +264,17 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { content: string ): ts.Diagnostic | undefined { // Make sure returned error is within the real document - if (diagnostic.range.start.line === 0 - || diagnostic.range.start.line > doc.lineCount - || diagnostic.range.start.character >= content.length + if ( + diagnostic.range.start.line === 0 || + diagnostic.range.start.line > doc.lineCount || + diagnostic.range.start.character >= content.length ) { return undefined; } const start = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(diagnostic.range.start)); - const length = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(diagnostic.range.end)) - start; + const length = + context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(diagnostic.range.end)) - start; const code = typeof diagnostic.code === 'number' ? diagnostic.code : cssErrorCode; return { code, @@ -300,11 +287,7 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { }; } - private translateHover( - hover: vscode.Hover, - position: ts.LineAndCharacter, - context: TemplateContext - ): ts.QuickInfo { + private translateHover(hover: vscode.Hover, position: ts.LineAndCharacter, context: TemplateContext): ts.QuickInfo { const contents: ts.SymbolDisplayPart[] = []; const convertPart = (hoverContents: typeof hover.contents) => { if (typeof hoverContents === 'string') { @@ -316,13 +299,17 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { } }; convertPart(hover.contents); - const start = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(hover.range ? hover.range.start : position)); + const start = context.toOffset( + this.virtualDocumentFactory.fromVirtualDocPosition(hover.range ? hover.range.start : position) + ); return { kind: this.typescript.ScriptElementKind.unknown, kindModifiers: '', textSpan: { start, - length: hover.range ? context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(hover.range.end)) - start : 1, + length: hover.range + ? context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(hover.range.end)) - start + : 1, }, displayParts: [], documentation: contents, @@ -330,51 +317,54 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { }; } - private translateCodeActions( - context: TemplateContext, - codeActions: vscode.Command[] - ): ts.CodeAction[] { + private translateCodeActions(context: TemplateContext, codeActions: vscode.Command[]): ts.CodeAction[] { const actions: ts.CodeAction[] = []; for (const vsAction of codeActions) { if (vsAction.command !== '_css.applyCodeAction') { continue; } - const edits = vsAction.arguments && vsAction.arguments[2] as vscode.TextEdit[]; + const edits = vsAction.arguments && (vsAction.arguments[2] as vscode.TextEdit[]); if (edits) { actions.push({ description: vsAction.title, - changes: edits.map(edit => this.translateTextEditToFileTextChange(context, edit)), + changes: edits.map((edit) => this.translateTextEditToFileTextChange(context, edit)), }); } } return actions; } - private translateTextEditToFileTextChange( - context: TemplateContext, - textEdit: vscode.TextEdit - ): ts.FileTextChanges { + private translateTextEditToFileTextChange(context: TemplateContext, textEdit: vscode.TextEdit): ts.FileTextChanges { const start = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(textEdit.range.start)); const end = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition(textEdit.range.end)); return { fileName: context.fileName, - textChanges: [{ - newText: textEdit.newText, - span: { - start, - length: end - start, + textChanges: [ + { + newText: textEdit.newText, + span: { + start, + length: end - start, + }, }, - }], + ], }; } - private translateOutliningSpan( - context: TemplateContext, - range: FoldingRange - ): ts.OutliningSpan { - const startOffset = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition({ line: range.startLine, character: range.startCharacter || 0 })); - const endOffset = context.toOffset(this.virtualDocumentFactory.fromVirtualDocPosition({ line: range.endLine, character: range.endCharacter || 0 })); + private translateOutliningSpan(context: TemplateContext, range: FoldingRange): ts.OutliningSpan { + const startOffset = context.toOffset( + this.virtualDocumentFactory.fromVirtualDocPosition({ + line: range.startLine, + character: range.startCharacter || 0, + }) + ); + const endOffset = context.toOffset( + this.virtualDocumentFactory.fromVirtualDocPosition({ + line: range.endLine, + character: range.endCharacter || 0, + }) + ); const span = { start: startOffset, length: endOffset - startOffset, @@ -390,10 +380,8 @@ export class StyledTemplateLanguageService implements TemplateLanguageService { } } -function filterScssCompletionItems( - items: vscode.CompletionItem[] -): vscode.CompletionItem[] { - return items.filter(item => (item.kind === vscode.CompletionItemKind.Function && item.label.substr(0, 1) === ':')); +function filterScssCompletionItems(items: vscode.CompletionItem[]): vscode.CompletionItem[] { + return items.filter((item) => item.kind === vscode.CompletionItemKind.Function && item.label.substr(0, 1) === ':'); } function translateCompletionItemsToCompletionInfo( @@ -409,7 +397,7 @@ function translateCompletionItemsToCompletionInfo( isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, - entries: items.items.map(x => translateCompetionEntry(typescript, x, doc, wrapper)), + entries: items.items.map((x) => translateCompetionEntry(typescript, x, doc, wrapper)), }; } @@ -446,10 +434,7 @@ function translateCompetionEntry( }; } -function translateCompletionItemKind( - typescript: typeof ts, - kind: vscode.CompletionItemKind -): ts.ScriptElementKind { +function translateCompletionItemKind(typescript: typeof ts, kind: vscode.CompletionItemKind): ts.ScriptElementKind { switch (kind) { case vscode.CompletionItemKind.Method: return typescript.ScriptElementKind.memberFunctionElement; @@ -513,14 +498,14 @@ function translateSeverity( } } -function toDisplayParts( - text: string | vscode.MarkupContent | undefined -): ts.SymbolDisplayPart[] { +function toDisplayParts(text: string | vscode.MarkupContent | undefined): ts.SymbolDisplayPart[] { if (!text) { return []; } - return [{ - kind: 'text', - text: typeof text === 'string' ? text : text.value, - }]; -} \ No newline at end of file + return [ + { + kind: 'text', + text: typeof text === 'string' ? text : text.value, + }, + ]; +} diff --git a/src/_logger.ts b/src/_logger.ts index eece22f..b3f7d02 100644 --- a/src/_logger.ts +++ b/src/_logger.ts @@ -1,12 +1,11 @@ import { Logger } from 'typescript-template-language-service-decorator'; import { pluginName } from './_config'; +import * as ts from 'typescript/lib/tsserverlibrary'; export class LanguageServiceLogger implements Logger { - constructor( - private readonly info: ts.server.PluginCreateInfo - ) { } + constructor(private readonly info: ts.server.PluginCreateInfo) {} public log(msg: string) { this.info.project.projectService.logger.info(`[${pluginName}] ${msg}`); } -} \ No newline at end of file +} diff --git a/src/_plugin.ts b/src/_plugin.ts index 2bf7f81..422429a 100644 --- a/src/_plugin.ts +++ b/src/_plugin.ts @@ -9,13 +9,10 @@ import { getSubstitutions } from './_substituter'; import { StyledVirtualDocumentFactory } from './_virtual-document-provider'; export class StyledPlugin { - private _logger?: LanguageServiceLogger; private readonly _configManager = new ConfigurationManager(); - public constructor( - private readonly typescript: typeof ts - ) { } + public constructor(private readonly typescript: typeof ts) {} public create(info: ts.server.PluginCreateInfo): ts.LanguageService { this._logger = new LanguageServiceLogger(info); @@ -32,9 +29,15 @@ export class StyledPlugin { this.typescript, info.languageService, info.project, - new StyledTemplateLanguageService(this.typescript, this._configManager, new StyledVirtualDocumentFactory(), this._logger), + new StyledTemplateLanguageService( + this.typescript, + this._configManager, + new StyledVirtualDocumentFactory(), + this._logger + ), getTemplateSettings(this._configManager), - { logger: this._logger }); + { logger: this._logger } + ); } public onConfigurationChanged(config: any) { @@ -47,7 +50,9 @@ export class StyledPlugin { export function getTemplateSettings(configManager: ConfigurationManager): TemplateSettings { return { - get tags() { return configManager.config.tags; }, + get tags() { + return configManager.config.tags; + }, enableForStringWithSubstitutions: true, getSubstitutions(templateString, spans): string { return getSubstitutions(templateString, spans); diff --git a/src/_virtual-document-provider.ts b/src/_virtual-document-provider.ts index 9d61efb..35a0a17 100644 --- a/src/_virtual-document-provider.ts +++ b/src/_virtual-document-provider.ts @@ -1,7 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. import { TemplateContext } from 'typescript-template-language-service-decorator'; -import {TextDocument, Position} from 'vscode-languageserver-textdocument'; +import { TextDocument, Position } from 'vscode-languageserver-textdocument'; +import * as ts from 'typescript/lib/tsserverlibrary'; /** * Handles mapping between template contents to virtual documents. @@ -25,9 +26,7 @@ export class StyledVirtualDocumentFactory implements VirtualDocumentProvider { private static readonly wrapperPreRoot = ':root{\n'; private static readonly wrapperPreKeyframes = '@keyframes custom {\n'; - public createVirtualDocument( - context: TemplateContext - ): TextDocument { + public createVirtualDocument(context: TemplateContext): TextDocument { const contents = `${this.getVirtualDocumentWrapper(context)}${context.text}\n}`; return { uri: 'untitled://embedded.scss', @@ -70,6 +69,8 @@ export class StyledVirtualDocumentFactory implements VirtualDocumentProvider { public getVirtualDocumentWrapper(context: TemplateContext): string { const tag = (context.node.parent as ts.Node & { tag: any })?.tag?.escapedText; - return tag === 'keyframes' ? StyledVirtualDocumentFactory.wrapperPreKeyframes : StyledVirtualDocumentFactory.wrapperPreRoot; + return tag === 'keyframes' + ? StyledVirtualDocumentFactory.wrapperPreKeyframes + : StyledVirtualDocumentFactory.wrapperPreRoot; } } diff --git a/src/index.ts b/src/index.ts index 3313e1c..1b47c7d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,5 +3,4 @@ import * as ts from 'typescript/lib/tsserverlibrary'; import { StyledPlugin } from './_plugin'; -export = (mod: { typescript: typeof ts }) => - new StyledPlugin(mod.typescript); +export = (mod: { typescript: typeof ts }) => new StyledPlugin(mod.typescript); From 19d21cfb93e41eaa3eb5127156b34cf625fe0610 Mon Sep 17 00:00:00 2001 From: jwilliams720 Date: Thu, 1 Dec 2022 11:56:33 +0000 Subject: [PATCH 2/3] update lockfile --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 78ab4a1..399884f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@styled/typescript-styled-plugin", - "version": "0.19.0", + "version": "0.20.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@styled/typescript-styled-plugin", - "version": "0.19.0", + "version": "0.20.0", "license": "MIT", "dependencies": { "@vscode/emmet-helper": "^2.8.4", From 80484c0f44c895475843dab5d1f1e395de0433b5 Mon Sep 17 00:00:00 2001 From: jwilliams720 Date: Thu, 1 Dec 2022 12:17:32 +0000 Subject: [PATCH 3/3] update CI --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c088a6b..80cac61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: - node-version: 14.x + node-version: 18 - run: npm install - name: Linting run: npm run lint @@ -28,9 +28,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: - node-version: 14.x + node-version: 18 - run: npm install - name: Compiling run: npm run compile @@ -41,9 +41,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: - node-version: 14.x + node-version: 18 - run: npm install - name: Compiling run: npm run compile @@ -55,9 +55,9 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: - node-version: 14.x + node-version: 18 - run: npm install - run: npm install working-directory: ./e2e