Skip to content

Commit

Permalink
Single file TSX transform (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
znck authored Sep 23, 2022
1 parent 1dc5763 commit ace9cb5
Show file tree
Hide file tree
Showing 212 changed files with 17,736 additions and 21,859 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ _templates/
samples/**
coverage/
@types/
**/*.spec.ts
35 changes: 15 additions & 20 deletions .github/workflows-source/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ on:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'

.pnpm: &pnpm
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: '6.2.5'
version: '7.12.1'
run_install: |
- recursive: true
args: [--frozen-lockfile]
Expand Down Expand Up @@ -91,10 +91,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node_version: ['16']
node_version: ['18']
include:
- os: ubuntu-latest
node: '16'
node: '18'
command: 'coverage'
runs-on: ${{ matrix.os }}
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}
Expand All @@ -117,13 +117,15 @@ jobs:
uses: codecov/codecov-action@v1
with:
file: ./coverage/coverage-final.json
dts:
name: DTS
runs-on: ubuntu-latest
steps:
- *setup
- name: Test
run: pnpm test:types

# TODO: Enable this.
# dts:
# name: DTS
# runs-on: ubuntu-latest
# steps:
# - *setup
# - name: Test
# run: pnpm test:types

eslint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -172,18 +174,11 @@ jobs:
files: |
extensions/*/*.vsix
check_release:
name: Check Release
runs-on: ubuntu-latest
needs: unit
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- run: echo 'ok'

release:
name: Release
runs-on: ubuntu-latest
needs: check_release
needs: unit
if: startsWith(github.event.ref, 'refs/tags/v')
concurrency:
group: release
cancel-in-progress: false
Expand Down
66 changes: 13 additions & 53 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: 6.2.5
version: 7.12.1
run_install: |
- recursive: true
args: [--frozen-lockfile]
Expand Down Expand Up @@ -72,10 +72,10 @@ jobs:
- ubuntu-latest
- windows-latest
node_version:
- '16'
- '18'
include:
- os: ubuntu-latest
node: '16'
node: '18'
command: coverage
runs-on: ${{ matrix.os }}
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: 6.2.5
version: 7.12.1
run_install: |
- recursive: true
args: [--frozen-lockfile]
Expand All @@ -123,40 +123,6 @@ jobs:
uses: codecov/codecov-action@v1
with:
file: ./coverage/coverage-final.json
dts:
name: DTS
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache node packages
uses: actions/cache@v2
env:
cache-name: pnpm-modules
with:
key: >-
${{ runner.os }}-build-${{ env.cache-name }}-${{
hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
path: |
~/.pnpm-store
${{ github.workspace }}/.pnpm
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: 6.2.5
run_install: |
- recursive: true
args: [--frozen-lockfile]
- name: Test
run: pnpm test:types
eslint:
runs-on: ubuntu-latest
needs: build
Expand All @@ -181,11 +147,11 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: 6.2.5
version: 7.12.1
run_install: |
- recursive: true
args: [--frozen-lockfile]
Expand Down Expand Up @@ -226,11 +192,11 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: 6.2.5
version: 7.12.1
run_install: |
- recursive: true
args: [--frozen-lockfile]
Expand Down Expand Up @@ -272,17 +238,11 @@ jobs:
prerelease: true
files: |
extensions/*/*.vsix
check_release:
name: Check Release
runs-on: ubuntu-latest
needs: unit
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- run: echo 'ok'
release:
name: Release
runs-on: ubuntu-latest
needs: check_release
needs: unit
if: startsWith(github.event.ref, 'refs/tags/v')
concurrency:
group: release
cancel-in-progress: false
Expand All @@ -307,11 +267,11 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '18'
- name: Setup PNPM
uses: pnpm/action-setup@v2.0.1
with:
version: 6.2.5
version: 7.12.1
run_install: |
- recursive: true
args: [--frozen-lockfile]
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
samples/**/*
packages/compiler-tsx/test/fixtures/**/*
pnpm-lock.yaml
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"cSpell.words": [
"Builtins",
"Codegen",
"deindent",
"endregion",
"hygen",
"lcfirst",
"onwarn",
"textdocument",
"treeshake",
"typecheck",
"ucfirst",
"Uncapitalize",
"vetur",
"vuedx"
],
Expand Down
2 changes: 1 addition & 1 deletion _templates/package/new/api-extractor.json.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ to: packages/<%= name %>/api-extractor.json
"compiler": {
"tsconfigFilePath": "<projectFolder>/tsconfig.json",
"overrideTsconfig": {},
"skipLibCheck": true
"skipLibCheck": false
},
"apiReport": {
"enabled": true,
Expand Down
5 changes: 4 additions & 1 deletion extensions/vscode-vue-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
"sources": {
"src/index.ts": [
{
"format": "commonjs",
"format": "esm",
"file": "dist/index.js",
"bundle": {
"format": "cjs",
"platform": "node",
"external": [
"vscode",
"@vuedx/typescript-plugin-vue"
Expand Down Expand Up @@ -324,6 +326,7 @@
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@types/node": "^10.12.0",
"@types/vscode": "^1.63.0",
"typescript": "^4.6.3",
"vsce": "2.6.7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { injectable, inject } from 'inversify'
import { first } from '@vuedx/shared'
import { inject, injectable } from 'inversify'
import vscode from 'vscode'
import { PluginCommunicationService } from '../services/PluginCommunicationService'
import { getVirtualFileUri } from '../utils/uri'
Expand All @@ -25,11 +26,9 @@ export class OpenVirtualFileCommand {
return
}

const position = editor.document.offsetAt(editor.selection.start)
const fileName = await this.plugin.first(async (connection) => {
return await connection.getVirtualFileAt(
editor.document.fileName,
position,
return first(
await connection.getRelatedVirtualFiles(editor.document.fileName),
)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
isProjectRuntimeFile,
isVueJsxFile,
isVueSFCDescriptorFile,
isVueTemplateASTFile,
isVueTsFile,
parseFileName,
ucfirst,
isVueTemplateASTFile, isVueTsxFile,
parseFileName
} from '@vuedx/shared'
import { inject, injectable } from 'inversify'
import { basename } from 'path'
Expand Down Expand Up @@ -54,20 +53,11 @@ export class SelectVirtualFileCommand {
}

private getDisplayName(fileName: string): string {
if (isVueTsFile(fileName)) return 'Virtual Module'
if (isVueTsxFile(fileName) || isVueJsxFile(fileName))
return 'Virtual Module'
if (isProjectRuntimeFile(fileName)) return 'Project Globals'
if (isVueSFCDescriptorFile(fileName)) return 'SFC Descriptor'
if (isVueTemplateASTFile(fileName)) return 'Template AST'
const parsed = parseFileName(fileName)
if (parsed.type === 'virtual') {
if (parsed.blockType === 'sript') {
return parsed.setup === true ? 'Virtual Script Setup' : 'Virtual Script'
} else if (parsed.blockIndex == null) {
return `Virtual ${ucfirst(parsed.blockType)}`
} else {
return `Virtual ${ucfirst(parsed.blockType)} ${parsed.blockIndex}`
}
}

return basename(fileName)
}
Expand Down
22 changes: 12 additions & 10 deletions extensions/vscode-vue-language-features/src/scheme/vue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isVueFile, parseFileName, VueVirtualFileName } from '@vuedx/shared'
import { isVueFile, parseFileName } from '@vuedx/shared'
import { inject, injectable } from 'inversify'
import vscode from 'vscode'
import { PluginCommunicationService } from '../services/PluginCommunicationService'
Expand All @@ -8,7 +8,8 @@ import { getVirtualFileNameFromUri } from '../utils/uri'
@injectable()
export class VueVirtualDocumentProvider
extends Installable
implements vscode.TextDocumentContentProvider {
implements vscode.TextDocumentContentProvider
{
constructor(
@inject(PluginCommunicationService)
private readonly plugin: PluginCommunicationService,
Expand Down Expand Up @@ -36,7 +37,7 @@ export class VueVirtualDocumentProvider
vscode.workspace.onDidOpenTextDocument(({ uri }) => {
if (uri.scheme === 'vue') {
const fileName = getVirtualFileNameFromUri(uri)
const parsed = parseFileName(fileName) as VueVirtualFileName
const parsed = parseFileName(fileName)
const openFiles = this.openVueFiles.get(parsed.fileName)
if (openFiles == null) {
this.openVueFiles.set(parsed.fileName, new Set([uri.toString()]))
Expand All @@ -48,7 +49,7 @@ export class VueVirtualDocumentProvider
vscode.workspace.onDidCloseTextDocument(({ uri }) => {
if (uri.scheme === 'vue') {
const fileName = getVirtualFileNameFromUri(uri)
const parsed = parseFileName(fileName) as VueVirtualFileName
const parsed = parseFileName(fileName)
const openFiles = this.openVueFiles.get(parsed.fileName)
if (openFiles == null) return
openFiles.delete(uri.toString())
Expand Down Expand Up @@ -79,12 +80,13 @@ export class VueVirtualDocumentProvider

const start = textEditor.document.offsetAt(editor.selection.start)
const end = textEditor.document.offsetAt(editor.selection.end)
const result = await this.plugin.first(async (conneciton) => {
return await conneciton.findGeneratedFileAndRange(
fileName,
start,
end,
)
const result = await this.plugin.first(async (_conneciton) => {
console.log(start, end)
return null as null | {
fileName: string
start: number
end: number
} // TODO: fix this
})

// not found or cancelled
Expand Down
Loading

0 comments on commit ace9cb5

Please sign in to comment.