Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add css-in-js tag support #26

Merged
merged 39 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cb3a06f
feat: support js|ts|tsreact|jsreact
Jan 17, 2023
8c56261
feat: tsEssential integration
Ilanaya Jan 20, 2023
afab564
feat: make usedRules work
Ilanaya Jan 20, 2023
ca41643
add comment: explain tokens
zardoy Jan 21, 2023
91b7858
update unocss preset (tailwind) to latest with new rules
zardoy Jan 21, 2023
8ab3c88
Update src/extension.ts
Ilanaya Jan 21, 2023
71329a0
fix: make ts-essential-plugin api call optional
Jan 21, 2023
262e960
fix: handle different langs word patterns
Jan 21, 2023
23cc7d2
fix: make suggestion work in every tagged template part
Jan 25, 2023
333c8fa
fix: pass range instead of func
Jan 25, 2023
5549e05
fix: remove dev command registration
Jan 25, 2023
1ecfbb7
chore: add ext dependency
Jan 25, 2023
cc7451b
fix: add attemps counter
Jan 25, 2023
7fc3673
feat: add tests
Jan 25, 2023
9a8ba35
fix: make return type more consistant
Jan 25, 2023
e558260
simplify arch: don't pass down completion range
zardoy Jan 27, 2023
9bf7570
don't use weird & annoying method of retriggering completion in any l…
zardoy Jan 27, 2023
ca0b43a
typecheck on build!
zardoy Jan 27, 2023
a2fcd23
cache static shortcuts between compeltion calls
zardoy Jan 27, 2023
3e5287e
call duplication
zardoy Jan 27, 2023
c976128
introduce usage of super useful string-fn
zardoy Jan 30, 2023
b68c4b4
feat: inline variables of abbreviations
zardoy Feb 1, 2023
e6e5b5b
feat: add settings to edit or add shortcuts
zardoy Feb 1, 2023
626b072
readme: remove ext dependency, add readme
Feb 1, 2023
41ca856
fix: rollback jsoc lang annotations
Feb 1, 2023
a05cc8e
markdownlint
zardoy Feb 2, 2023
d019ceb
fix: pass only last node range
Feb 2, 2023
5a172f5
fix
Feb 2, 2023
fff3999
fix: remove failing tests, error spamming, fix parse css recursion calls
Feb 3, 2023
f1a8bf6
add tests :mark:
zardoy Feb 4, 2023
671d936
fix undefined index crashes
zardoy Feb 4, 2023
9d8d5b1
fix prettier
zardoy Feb 4, 2023
c050be4
trigger
zardoy Feb 5, 2023
9a2a4db
fix prettier in ci file
zardoy Feb 5, 2023
f8cb670
run checkout before checking
zardoy Feb 5, 2023
48785fc
use local prettier
zardoy Feb 5, 2023
a5998cb
install local prettier first...
zardoy Feb 5, 2023
7721fa1
try almost 2x increase timeout
zardoy Feb 5, 2023
681c657
activate ts plugin earlier
zardoy Feb 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
"onLanguage:scss",
"onLanguage:sass",
"onLanguage:less",
"onLanguage:vue"
"onLanguage:vue",
"onLanguage:javascript",
"onLanguage:typescript",
"onLanguage:javascriptreact",
"onLanguage:typescriptreact"
],
"contributes": {},
"scripts": {
Expand Down
19 changes: 17 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ export const activate = () => {

abbreviationShorthand.lastIndex = 0
})
const taggedTemplateStylesLangs = new Set(['javascript', 'typescript', 'javascriptreact', 'typescriptreact'])

vscode.languages.registerCompletionItemProvider(['css', 'scss', 'less', 'vue'], {
vscode.languages.registerCompletionItemProvider(['css', 'scss', 'less', 'vue', ...taggedTemplateStylesLangs], {
async provideCompletionItems(document, position, token, context) {
const completions: vscode.CompletionItem[] = []
// exit early on line start
if (!position.character) return
const stylesRange = await getStylesRange(document, position)
const { kindName, start, end } =
((await vscode.commands.executeCommand('tsEssentialPlugins.getNodeAtPosition', { offset: document.offsetAt(position) })) as any) ?? {}
Ilanaya marked this conversation as resolved.
Show resolved Hide resolved

// TODO: make it work in LastTemplateToken cases
const supportedSyntaxKinds = new Set(['TemplateHead', 'TemplateMiddle', 'FirstTemplateToken' /* 'LastTemplateToken ' */])

const isInTaggedTemplate =
supportedSyntaxKinds.has(kindName) &&
/\s*.*?(styled|css)\.?.*/.test(document.getText(new vscode.Range(document.positionAt(start).with(undefined, 0), document.positionAt(start))))
Ilanaya marked this conversation as resolved.
Show resolved Hide resolved

const stylesRange =
taggedTemplateStylesLangs.has(document.languageId) && isInTaggedTemplate
? new vscode.Range(document.positionAt(start).translate(undefined, 1), document.positionAt(end).translate(undefined, -1))
: await getStylesRange(document, position)

if (!stylesRange) return

const virtualDocument: SimpleVirtualDocument = {
Expand Down
10 changes: 9 additions & 1 deletion src/parseCss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import postcssParser from 'postcss/lib/parse'
import Node from 'postcss/lib/node'
import Rule from 'postcss/lib/rule'
import { Declaration } from 'postcss'
import { Declaration, Root } from 'postcss'

const findUsedRules = (stylesContent: string, offset: number) => {
const usedRules = new Map<string, { value: string; offset: number }>()
Expand All @@ -28,6 +28,14 @@ const findUsedRules = (stylesContent: string, offset: number) => {

const foundNode = findPositionContainingNode(offset, parsed.nodes)

// styled component case
if (!foundNode && parsed instanceof Root && 'nodes' in parsed) {
for (const node of parsed.nodes as Node[])
if (node instanceof Declaration) {
usedRules.set(node.prop, { value: node.value, offset: node.source!.start!.offset })
}
}

if (foundNode instanceof Rule) {
for (const node of foundNode.nodes)
if (node instanceof Declaration) {
Expand Down