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

[pull] master from vuejs:master #102

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 2.1.0-insiders.6 (2024/4/25)

Download Pages: [GitHub Releases](https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.6), [爱发电电圈](https://afdian.net/p/f73a772602ab11efa33652540025c377)

> [Join the Insiders Program](https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition) for more exclusive features and updates.

### Features

- Check for Insiders version updates on startup
- Support reactions visualization for TS document

### Bug Fixes

- Fixed some incorrect situations in reactions analysis

### Other Changes

- Merged [v2.0.14...a69909e81](https://github.com/vuejs/language-tools/compare/v2.0.14...a69909e81).

## 2.1.0-insiders.5 (2024/4/22)

Download Pages: [GitHub Releases](https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.5), [爱发电电圈](https://afdian.net/p/25aca47c004e11ef8b445254001e7c00)
Expand Down
132 changes: 114 additions & 18 deletions extensions/vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as splitEditors from './features/splitEditors';
import * as semver from 'semver';
import * as fs from 'fs';
import * as path from 'path';
import { quickPick } from '@volar/vscode/lib/common';

let client: lsp.BaseLanguageClient;

Expand All @@ -28,7 +29,7 @@ export async function activate(context: vscode.ExtensionContext, createLc: Creat
function tryActivate() {
if (
vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'vue')
|| (config.server.vitePress.supportMdFile && vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'vue'))
|| (config.server.vitePress.supportMdFile && vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'markdown'))
|| (config.server.petiteVue.supportHtmlFile && vscode.window.visibleTextEditors.some(editor => editor.document.languageId === 'html'))
) {
doActivate(context, createLc);
Expand Down Expand Up @@ -228,26 +229,121 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang

const item = vscode.languages.createLanguageStatusItem('vue-insider', 'vue');
if (!context.extension.packageJSON.version.includes('-insider')) {
item.text = '✨ Get Vue - Official Insiders';
item.text = '✨ Get Insiders Edition';
item.severity = vscode.LanguageStatusSeverity.Warning;
item.command = {
title: 'More Info',
command: 'vscode.open',
arguments: ['https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition'],
};
}
else {
item.text = '🚀 Vue - Official Insiders';
item.detail = 'Installed';
item.command = {
title: 'Changelog',
command: 'vue-insiders.checkUpdate',
};
vscode.commands.registerCommand('vue-insiders.checkUpdate', () => {
const updateUrl = 'https://github.com/vuejs/language-tools/blob/master/CHANGELOG.md';
vscode.env.openExternal(vscode.Uri.parse(updateUrl));
});
item.text = '🚀 Insiders Edition';
}
item.detail = 'Checking for Updates...';
item.busy = true;
fetch('https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json')
.then(res => res.json())
.then((json: {
latest: string;
versions: {
version: string;
date: string;
downloads: {
GitHub: string;
AFDIAN: string;
};
}[];
}) => {
item.detail = undefined;
item.command = {
title: 'Select Version',
command: 'vue-insiders.update',
};
if (
json.versions.some(version => version.version === context.extension.packageJSON.version)
&& context.extension.packageJSON.version !== json.latest
) {
item.detail = 'New Version Available!';
item.severity = vscode.LanguageStatusSeverity.Warning;
}
vscode.commands.registerCommand('vue-insiders.update', async () => {
const quickPickItems: { [version: string]: vscode.QuickPickItem; } = {};
for (const { version, date } of json.versions) {
let description = date;
if (context.extension.packageJSON.version === version) {
description += ' (current)';
}
quickPickItems[version] = {
label: version,
description,
};
}
const version = await quickPick([quickPickItems, {
learnMore: {
label: 'Learn more about Insiders Edition',
},
joinViaGitHub: {
label: 'Join via GitHub Sponsors',
},
joinViaAFDIAN: {
label: 'Join via AFDIAN (爱发电)',
},
}]);
if (version === 'learnMore') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition'));
}
else if (version === 'joinViaGitHub') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/johnsoncodehk'));
}
else if (version === 'joinViaAFDIAN') {
vscode.env.openExternal(vscode.Uri.parse('https://afdian.net/a/johnsoncodehk'));
}
else {
const downloads = json.versions.find(v => v.version === version)?.downloads;
if (downloads) {
const quickPickItems: { [key: string]: vscode.QuickPickItem; } = {
GitHub: {
label: `${version} - GitHub Releases`,
description: 'Access via GitHub Sponsors',
detail: downloads.GitHub,
},
AFDIAN: {
label: `${version} - Insiders 电圈`,
description: 'Access via AFDIAN (爱发电)',
detail: downloads.AFDIAN,
},
};
const otherItems: { [key: string]: vscode.QuickPickItem; } = {
learnMore: {
label: 'Learn more about Insiders Edition',
},
joinViaGitHub: {
label: 'Join via GitHub Sponsors',
},
joinViaAFDIAN: {
label: 'Join via AFDIAN (爱发电)',
},
};
const option = await quickPick([quickPickItems, otherItems]);
if (option === 'learnMore') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/vuejs/language-tools/wiki/Get-Insiders-Edition'));
}
else if (option === 'joinViaGitHub') {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/johnsoncodehk'));
}
else if (option === 'joinViaAFDIAN') {
vscode.env.openExternal(vscode.Uri.parse('https://afdian.net/a/johnsoncodehk'));
}
else if (option) {
vscode.env.openExternal(vscode.Uri.parse(downloads[option as keyof typeof downloads]));
}
}
}
});
})
.catch(() => {
item.detail = 'Failed to Fetch Versions';
item.severity = vscode.LanguageStatusSeverity.Warning;
})
.finally(() => {
item.busy = false;
});

async function requestReloadVscode(msg: string) {
const reload = await vscode.window.showInformationMessage(msg, 'Reload Window');
Expand Down Expand Up @@ -335,4 +431,4 @@ async function getInitializationOptions(
],
},
};
}
};
53 changes: 53 additions & 0 deletions insiders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"latest": "2.1.0-insiders.6",
"versions": [
{
"version": "2.1.0-insiders.6",
"date": "2024-4-25",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.6",
"AFDIAN": "https://afdian.net/p/f73a772602ab11efa33652540025c377"
}
},
{
"version": "2.1.0-insiders.5",
"date": "2024-4-22",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.5",
"AFDIAN": "https://afdian.net/p/25aca47c004e11ef8b445254001e7c00"
}
},
{
"version": "2.1.0-insiders.4",
"date": "2024-4-10",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.4",
"AFDIAN": "https://afdian.net/p/46a5f4a8f72011ee97fe52540025c377"
}
},
{
"version": "2.1.0-insiders.3",
"date": "2024-4-7",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.3",
"AFDIAN": "https://afdian.net/p/5bf99cfaf4ec11ee9e1f5254001e7c00"
}
},
{
"version": "2.1.0-insiders.2",
"date": "2024-4-4",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.3",
"AFDIAN": "https://afdian.net/p/d59d0dd8f29611ee88945254001e7c00"
}
},
{
"version": "2.1.0-insiders.1",
"date": "2024-3-28",
"downloads": {
"GitHub": "https://github.com/volarjs/insiders/releases/tag/v2.1.0-insiders.1",
"AFDIAN": "https://afdian.net/p/ba0901a2edce11ee8f2e52540025c377"
}
}
]
}
2 changes: 1 addition & 1 deletion packages/language-plugin-pug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"dependencies": {
"@volar/source-map": "2.2.0-alpha.10",
"volar-service-pug": "0.0.38"
"volar-service-pug": "0.0.40"
}
}
2 changes: 1 addition & 1 deletion packages/language-server/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ connection.onRequest(ParseSFCRequest.type, params => {
connection.onRequest(DetectNameCasingRequest.type, async params => {
const languageService = await getService(params.textDocument.uri);
if (languageService) {
return await detect(languageService.context, params.textDocument.uri, getTsPluginClient(languageService.context));
return await detect(languageService.context, params.textDocument.uri);
}
});

Expand Down
53 changes: 17 additions & 36 deletions packages/language-service/lib/ideFeatures/nameCasing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,9 @@ export async function convertAttrName(
return edits;
}

export async function getNameCasing(
context: ServiceContext,
uri: string,
tsPluginClient?: typeof import('@vue/typescript-plugin/lib/client'),
) {
export async function getNameCasing(context: ServiceContext, uri: string) {

const detected = await detect(context, uri, tsPluginClient);
const detected = await detect(context, uri);
const [attr, tag] = await Promise.all([
context.env.getConfiguration?.<'autoKebab' | 'autoCamel' | 'kebab' | 'camel'>('vue.complete.casing.props', uri),
context.env.getConfiguration?.<'autoKebab' | 'autoPascal' | 'kebab' | 'pascal'>('vue.complete.casing.tags', uri),
Expand All @@ -131,7 +127,6 @@ export async function getNameCasing(
export async function detect(
context: ServiceContext,
uri: string,
tsPluginClient?: typeof import('@vue/typescript-plugin/lib/client'),
): Promise<{
tag: TagNameCasing[],
attr: AttrNameCasing[],
Expand Down Expand Up @@ -176,39 +171,25 @@ export async function detect(
}
async function getTagNameCase(file: VueVirtualCode): Promise<TagNameCasing[]> {

const components = await tsPluginClient?.getComponentNames(file.fileName) ?? [];
const tagNames = getTemplateTagsAndAttrs(file);
const result: TagNameCasing[] = [];

let anyComponentUsed = false;

for (const component of components) {
if (tagNames.has(component) || tagNames.has(hyphenateTag(component))) {
anyComponentUsed = true;
break;
}
}
if (!anyComponentUsed) {
return []; // not sure component style, because do not have any component using in <template> for check
}
const result = new Set<TagNameCasing>();

for (const [tagName] of tagNames) {
// TagName
if (tagName !== hyphenateTag(tagName)) {
result.push(TagNameCasing.Pascal);
break;
}
}
for (const component of components) {
// Tagname -> tagname
// TagName -> tag-name
if (component !== hyphenateTag(component) && tagNames.has(hyphenateTag(component))) {
result.push(TagNameCasing.Kebab);
break;
if (file.sfc.template?.ast) {
for (const element of vue.forEachElementNode(file.sfc.template.ast)) {
if (element.tagType === 1 satisfies CompilerDOM.ElementTypes) {
if (element.tag !== hyphenateTag(element.tag)) {
// TagName
result.add(TagNameCasing.Pascal);
}
else {
// Tagname -> tagname
// TagName -> tag-name
result.add(TagNameCasing.Kebab);
}
}
}
}

return result;
return [...result];
}
}

Expand Down
Loading
Loading