From 071d4cde5843ecf76e9326f122a7c87f04fa244d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Aslan?= Date: Mon, 16 Oct 2023 03:20:33 +0200 Subject: [PATCH] v0.4.1 - fixed TypeScript IntelliSense support and did some cleanup --- package-lock.json | 4 +-- package.json | 32 ++----------------- src/completionItems/componentProps.js | 2 ++ src/completionProviders/templateAttributes.js | 5 +-- src/parsers/ast.js | 8 ++++- 5 files changed, 16 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3e7d3f3..b94144a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lightning-blits", - "version": "0.4.0", + "version": "0.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "lightning-blits", - "version": "0.4.0", + "version": "0.4.1", "dependencies": { "@babel/parser": "^7.22.11", "@babel/traverse": "^7.22.17", diff --git a/package.json b/package.json index c222743..b73d0a8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publisher": "lightningjs", "displayName": "Lightning Blits", "description": "Template syntax highlighting and code completion for the Lightning Blits framework", - "version": "0.4.0", + "version": "0.4.1", "repository": { "type": "git", "url": "https://github.com/lightning-js/blits-vscode-extension.git" @@ -42,41 +42,13 @@ "grammars": [ { "injectTo": [ - "source.js" - ], - "scopeName": "inline.custom-blits-html", - "path": "./syntaxes/embedded-html.json" - }, - { - "injectTo": [ + "source.js", "source.ts" ], "scopeName": "inline.custom-blits-html", "path": "./syntaxes/embedded-html.json" } ], - "languages": [ - { - "id": "javascript", - "extensions": [ - ".js" - ], - "aliases": [ - "JavaScript", - "javascript" - ] - }, - { - "id": "typescript", - "extensions": [ - ".ts" - ], - "aliases": [ - "TypeScript", - "typescript" - ] - } - ], "keybindings": [ { "key": "ctrl+/", diff --git a/src/completionItems/componentProps.js b/src/completionItems/componentProps.js index a4e42c3..f553627 100644 --- a/src/completionItems/componentProps.js +++ b/src/completionItems/componentProps.js @@ -56,6 +56,7 @@ module.exports = async (tag, attributes, doc, docAst) => { completionItem.insertText = new vscode.SnippetString( `${prop.key}="$0"` ) + completionItem.sortText = '0' + prop.key completionItems.push(completionItem) } @@ -69,6 +70,7 @@ module.exports = async (tag, attributes, doc, docAst) => { reactiveCompletionItem.insertText = new vscode.SnippetString( `${prop.key}="${prop.default ? prop.default : ''}$0"` ) + reactiveCompletionItem.sortText = '0' + `:${prop.key}` completionItems.push(reactiveCompletionItem) } }) diff --git a/src/completionProviders/templateAttributes.js b/src/completionProviders/templateAttributes.js index 2d834a3..98bf4e4 100644 --- a/src/completionProviders/templateAttributes.js +++ b/src/completionProviders/templateAttributes.js @@ -21,12 +21,13 @@ const completionItems = require('../completionItems') const parse = require('../parsers') module.exports = vscode.languages.registerCompletionItemProvider( - { language: 'javascript' }, + [{ language: 'javascript' }, { language: 'typescript' }], { // eslint-disable-next-line no-unused-vars async provideCompletionItems(document, position, token, context) { const currentDoc = document.getText() - const currentDocAst = parse.AST(currentDoc) + const fileExtension = document.uri.fsPath.split('.').pop() + const currentDocAst = parse.AST(currentDoc, fileExtension) if ( templateHelper.isCursorInsideTemplate(document, currentDocAst, position) diff --git a/src/parsers/ast.js b/src/parsers/ast.js index 0f043d7..714224a 100644 --- a/src/parsers/ast.js +++ b/src/parsers/ast.js @@ -17,10 +17,16 @@ const parser = require('@babel/parser') -module.exports = (code) => { +module.exports = (code, fileExtension) => { + let plugins = [] + if (fileExtension === 'ts') { + plugins.push('typescript') + } + try { return parser.parse(code, { sourceType: 'module', + plugins: plugins, }) } catch (e) { console.error('error parsing AST')