Skip to content

Commit

Permalink
refactor: organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Nov 2, 2024
1 parent 3ece839 commit 1dad045
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"typescript.format.semicolons": "insert",
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
},
"json.format.keepLines": true,
"typescript.tsdk": "node_modules/typescript/lib",
"[typescript]": {
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as semver from 'semver';
import { computed, useAllExtensions } from 'reactive-vscode';
import * as semver from 'semver';
import * as vscode from 'vscode';

const extensions = useAllExtensions();

Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/hybridMode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { computed, executeCommand, ref, useAllExtensions, useVscodeContext, watchEffect } from "reactive-vscode";
import * as semver from 'semver';
import * as vscode from 'vscode';
import { computed, executeCommand, ref, useAllExtensions, useVscodeContext, watchEffect } from "reactive-vscode";
import { incompatibleExtensions, unknownExtensions } from './compatibility';
import { config } from './config';

Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/languageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
executeCommand,
nextTick,
useActiveTextEditor,
useVisibleTextEditors,
useOutputChannel,
useCommand,
useOutputChannel,
useVisibleTextEditors,
useVscodeContext,
watch,
} from 'reactive-vscode';
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as lsp from '@volar/vscode';
import { AttrNameCasing, TagNameCasing } from '@vue/language-server/lib/types';
import * as vscode from 'vscode';
import * as lsp from '@volar/vscode';
import { attrNameCasings, tagNameCasings } from './features/nameCasing';
import { config } from './config';
import { attrNameCasings, tagNameCasings } from './features/nameCasing';

export const middleware: lsp.Middleware = {
...lsp.middleware,
Expand Down
6 changes: 3 additions & 3 deletions extensions/vscode/src/nodeClientMain.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createLabsInfo } from '@volar/vscode';
import * as lsp from '@volar/vscode/node';
import * as protocol from '@vue/language-server/protocol';
import * as fs from 'fs';
import * as vscode from 'vscode';
import * as lsp from '@volar/vscode/node';
import { defineExtension, executeCommand, extensionContext, onDeactivate } from 'reactive-vscode';
import * as vscode from 'vscode';
import { config } from './config';
import { enabledHybridMode, enabledTypeScriptPlugin } from './hybridMode';
import { activate as activateLanguageClient, deactivate as deactivateLanguageClient } from './languageClient';
import { config } from './config';
import { middleware } from './middleware';

export const { activate, deactivate } = defineExtension(async () => {
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/tests/grammar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as fs from 'fs';
import * as path from 'path';
import { describe, expect, it } from 'vitest';
import { createGrammarSnapshot } from 'vscode-tmlanguage-snapshot';

Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import { createCheckerByJsonConfigBase, createCheckerBase } from './lib/base';
import { createCheckerBase, createCheckerByJsonConfigBase } from './lib/base';
import type { MetaCheckerOptions } from './lib/types';

export * from './lib/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/component-meta/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { describe, expect, test } from 'vitest';
import { createChecker, createCheckerByJson, MetaCheckerOptions, ComponentMetaChecker, TypeMeta } from '..';
import { ComponentMetaChecker, createChecker, createCheckerByJson, MetaCheckerOptions, TypeMeta } from '..';

const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describe(`vue-component-meta ${withTsconfig ? 'with tsconfig' : 'without tsconfig'}`, () => {

Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/componentSelf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path-browserify';
import type { Code } from '../../types';
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
import type { TemplateCodegenContext } from '../template/context';
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
import { generateComponentSetupReturns, generateEmitsOption, generatePropsOption } from './component';
import type { ScriptCodegenContext } from './context';
import { codeFeatures, type ScriptCodegenOptions } from './index';
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type * as ts from 'typescript';
import type { ScriptRanges } from '../../parsers/scriptRanges';
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../types';
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
import { generateGlobalTypes } from '../globalTypes';
import type { TemplateCodegenContext } from '../template/context';
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
import { generateComponentSelf } from './componentSelf';
import { createScriptCodegenContext, ScriptCodegenContext } from './context';
import { generateScriptSetup, generateScriptSetupImports } from './scriptSetup';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Code } from '../../types';
import { endOfLine, newLine } from '../utils';
import type { ScriptCodegenContext } from './context';
import { ScriptCodegenOptions, codeFeatures } from './index';
import { generateCssClassProperty } from './template';
import { endOfLine, newLine } from '../utils';

export function* generateStyleModulesType(
options: ScriptCodegenOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as path from 'path-browserify';
import type * as ts from 'typescript';
import type { Code } from '../../types';
import { getSlotsPropertyName, hyphenateTag } from '../../utils/shared';
import { endOfLine, newLine } from '../utils';
import { TemplateCodegenContext, createTemplateCodegenContext } from '../template/context';
import { forEachInterpolationSegment } from '../template/interpolation';
import { generateStyleScopedClasses } from '../template/styleScopedClasses';
import { endOfLine, newLine } from '../utils';
import type { ScriptCodegenContext } from './context';
import { codeFeatures, type ScriptCodegenOptions } from './index';

Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/template/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type * as CompilerDOM from '@vue/compiler-dom';
import type { Code, VueCodeInformation } from '../../types';
import { InlayHintInfo } from '../inlayHints';
import { endOfLine, newLine, wrapWith } from '../utils';
import type { TemplateCodegenOptions } from './index';
import { InlayHintInfo } from '../inlayHints';

const _codeFeatures = {
all: {
Expand Down
8 changes: 4 additions & 4 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as CompilerDOM from '@vue/compiler-dom';
import type * as ts from 'typescript';
import { camelize, capitalize } from '@vue/shared';
import type * as ts from 'typescript';
import { getNodeText } from '../../parsers/scriptSetupRanges';
import type { Code, VueCodeInformation } from '../../types';
import { hyphenateTag } from '../../utils/shared';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { collectVars, createTsAst, endOfLine, newLine, variableNameRegex, wrapWith } from '../utils';
import { generateCamelized } from '../utils/camelized';
import type { TemplateCodegenContext } from './context';
Expand All @@ -12,11 +14,9 @@ import { generateElementEvents } from './elementEvents';
import { type FailedPropExpression, generateElementProps } from './elementProps';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateObjectProperty } from './objectProperty';
import { generatePropertyAccess } from './propertyAccess';
import { generateTemplateChild } from './templateChild';
import { generateObjectProperty } from './objectProperty';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { getNodeText } from '../../parsers/scriptSetupRanges';

const colonReg = /:/g;

Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { minimatch } from 'minimatch';
import { toString } from 'muggle-string';
import type { Code, VueCodeInformation, VueCompilerOptions } from '../../types';
import { hyphenateAttr, hyphenateTag } from '../../utils/shared';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { conditionWrapWith, variableNameRegex, wrapWith } from '../utils';
import { generateCamelized } from '../utils/camelized';
import { generateUnicode } from '../utils/unicode';
import type { TemplateCodegenContext } from './context';
import { generateEventArg, generateEventExpression } from './elementEvents';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { generateObjectProperty } from './objectProperty';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { generateUnicode } from '../utils/unicode';

export interface FailedPropExpression {
node: CompilerDOM.SimpleExpressionNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/template/slotOutlet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as CompilerDOM from '@vue/compiler-dom';
import type { Code } from '../../types';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { endOfLine, newLine, wrapWith } from '../utils';
import type { TemplateCodegenContext } from './context';
import { generateElementChildren } from './elementChildren';
import { generateElementProps } from './elementProps';
import type { TemplateCodegenOptions } from './index';
import { generateInterpolation } from './interpolation';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';

export function* generateSlotOutlet(
options: TemplateCodegenOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Code } from '../../types';
import type { TemplateCodegenContext } from './context';
import { endOfLine, newLine } from '../utils';
import type { TemplateCodegenContext } from './context';

export function* generateStyleScopedClasses(
ctx: TemplateCodegenContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/utils/camelized.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { capitalize } from '@vue/shared';
import type { Code, VueCodeInformation } from '../../types';
import { combineLastMapping } from '.';
import { combineLastMapping } from './index';

export function* generateCamelized(code: string, offset: number, info: VueCodeInformation): Generator<Code> {
const parts = code.split('-');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Code, VueCodeInformation } from '../../types';
import { combineLastMapping, wrapWith } from '.';
import { combineLastMapping, wrapWith } from './index';

export function* generateStringLiteralKey(code: string, offset?: number, info?: VueCodeInformation): Generator<Code> {
if (offset === undefined || !info) {
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/utils/unicode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { wrapWith } from '.';
import type { Code, VueCodeInformation } from '../../types';
import { wrapWith } from './index';

export function* generateUnicode(code: string, offset: number, info: VueCodeInformation): Generator<Code> {
if (needToUnicode(code)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/parsers/scriptRanges.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TextRange } from '../types';
import type * as ts from 'typescript';
import type { TextRange } from '../types';
import { getNodeText, getStartEnd, parseBindingRanges } from './scriptSetupRanges';

export interface ScriptRanges extends ReturnType<typeof parseScriptRanges> { }
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/parsers/scriptSetupRanges.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as ts from 'typescript';
import type { VueCompilerOptions, TextRange } from '../types';
import { collectIdentifiers } from '../codegen/utils';
import type { TextRange, VueCompilerOptions } from '../types';

export interface ScriptSetupRanges extends ReturnType<typeof parseScriptSetupRanges> { }

Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/plugins/vue-template-inline-ts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CodeInformation } from '@volar/language-core';
import { createTsAst } from '../codegen/utils';
import * as CompilerDOM from '@vue/compiler-dom';
import { isCompoundExpression } from '../codegen/template/elementEvents';
import { parseInterpolationNode } from '../codegen/template/templateChild';
import { parseVForNode } from '../codegen/template/vFor';
import { createTsAst } from '../codegen/utils';
import type { Code, Sfc, VueLanguagePlugin } from '../types';
import * as CompilerDOM from '@vue/compiler-dom';

const codeFeatures: CodeInformation = {
format: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-core/lib/utils/buildMappings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Segment } from 'muggle-string';
import type { Mapping } from '@volar/language-core';
import type { Segment } from 'muggle-string';

export function buildMappings<T>(chunks: Segment<T>[]) {
let length = 0;
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/language-core/lib/utils/parseSfc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CompilerError, SFCDescriptor, SFCBlock, SFCStyleBlock, SFCScriptBlock, SFCTemplateBlock, SFCParseResult } from '@vue/compiler-sfc';
import type { ElementNode, SourceLocation } from '@vue/compiler-dom';
import * as compiler from '@vue/compiler-dom';
import type { CompilerError, SFCBlock, SFCDescriptor, SFCParseResult, SFCScriptBlock, SFCStyleBlock, SFCTemplateBlock } from '@vue/compiler-sfc';
import { SFCStyleOverride } from '../types';

export function parse(source: string): SFCParseResult {
Expand Down
6 changes: 3 additions & 3 deletions packages/language-core/lib/utils/ts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { camelize } from '@vue/shared';
import type * as ts from 'typescript';
import { posix as path } from 'path-browserify';
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';
import { getAllExtensions } from '../languagePlugin';
import type * as ts from 'typescript';
import { generateGlobalTypes } from '../codegen/globalTypes';
import { getAllExtensions } from '../languagePlugin';
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';

export type ParsedCommandLine = ts.ParsedCommandLine & {
vueOptions: VueCompilerOptions;
Expand Down
2 changes: 1 addition & 1 deletion packages/language-plugin-pug/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SourceMap } from '@volar/source-map';
import type { VueLanguagePlugin } from '@vue/language-core';
import * as pug from 'volar-service-pug/lib/languageService';
import { SourceMap } from '@volar/source-map';

const plugin: VueLanguagePlugin = ({ modules }) => {

Expand Down
6 changes: 3 additions & 3 deletions packages/language-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import { create as createTypeScriptTwoslashQueriesPlugin } from 'volar-service-t
import { create as createTypeScriptDocCommentTemplatePlugin } from 'volar-service-typescript/lib/plugins/docCommentTemplate';
import { create as createTypeScriptSyntacticPlugin } from 'volar-service-typescript/lib/plugins/syntactic';
import { create as createCssPlugin } from './lib/plugins/css';
import { create as createVueAutoDefineAssignmentPlugin } from './lib/plugins/vue-complete-define-assignment';
import { create as createVueAutoDotValuePlugin } from './lib/plugins/vue-autoinsert-dotvalue';
import { create as createVueAutoAddSpacePlugin } from './lib/plugins/vue-autoinsert-space';
import { create as createVueCompleteDefineAssignmentPlugin } from './lib/plugins/vue-complete-define-assignment';
import { create as createVueDirectiveCommentsPlugin } from './lib/plugins/vue-directive-comments';
import { create as createVueDocumentDropPlugin } from './lib/plugins/vue-document-drop';
import { create as createVueDocumentLinksPlugin } from './lib/plugins/vue-document-links';
import { create as createVueExtractFilePlugin } from './lib/plugins/vue-extract-file';
import { create as createVueInlayHintsPlugin } from './lib/plugins/vue-inlayhints';
import { create as createVueSfcPlugin } from './lib/plugins/vue-sfc';
import { create as createVueTemplatePlugin } from './lib/plugins/vue-template';
import { create as createVueTwoslashQueriesPlugin } from './lib/plugins/vue-twoslash-queries';
import { create as createVueInlayHintsPlugin } from './lib/plugins/vue-inlayhints';

import { parse, VueCompilerOptions } from '@vue/language-core';
import { proxyLanguageServiceForVue } from '@vue/typescript-plugin/lib/common';
Expand Down Expand Up @@ -198,7 +198,7 @@ function getCommonLanguageServicePlugins(
createVueTwoslashQueriesPlugin(getTsPluginClient),
createVueDocumentLinksPlugin(),
createVueDocumentDropPlugin(ts, getTsPluginClient),
createVueAutoDefineAssignmentPlugin(),
createVueCompleteDefineAssignmentPlugin(),
createVueAutoDotValuePlugin(ts, getTsPluginClient),
createVueAutoAddSpacePlugin(),
createVueInlayHintsPlugin(ts),
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/lib/plugins/vue-inlayhints.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { LanguageServicePluginInstance } from '@volar/language-service';
import { tsCodegen, VueVirtualCode } from '@vue/language-core';
import { collectIdentifiers } from '@vue/language-core/lib/codegen/common';

Check failure on line 3 in packages/language-service/lib/plugins/vue-inlayhints.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@vue/language-core/lib/codegen/common' or its corresponding type declarations.

Check failure on line 3 in packages/language-service/lib/plugins/vue-inlayhints.ts

View workflow job for this annotation

GitHub Actions / build (18, macos-latest)

Cannot find module '@vue/language-core/lib/codegen/common' or its corresponding type declarations.

Check failure on line 3 in packages/language-service/lib/plugins/vue-inlayhints.ts

View workflow job for this annotation

GitHub Actions / build (18, ubuntu-latest)

Cannot find module '@vue/language-core/lib/codegen/common' or its corresponding type declarations.
import type * as ts from 'typescript';
import type * as vscode from 'vscode-languageserver-protocol';
import { URI } from 'vscode-uri';
import type { LanguageServicePlugin } from '../types';
import type * as ts from 'typescript';
import { collectIdentifiers } from '@vue/language-core/lib/codegen/common';

export function create(ts: typeof import('typescript')): LanguageServicePlugin {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/lib/plugins/vue-sfc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { LanguageServicePlugin, LanguageServicePluginInstance, LanguageServiceContext } from '@volar/language-service';
import type { LanguageServiceContext, LanguageServicePlugin, LanguageServicePluginInstance } from '@volar/language-service';
import * as vue from '@vue/language-core';
import { create as createHtmlService } from 'volar-service-html';
import * as html from 'vscode-html-languageservice';
import type * as vscode from 'vscode-languageserver-protocol';
import type { TextDocument } from 'vscode-languageserver-textdocument';
import { loadLanguageBlocks } from './data';
import { URI } from 'vscode-uri';
import { loadLanguageBlocks } from './data';

let sfcDataProvider: html.IHTMLDataProvider | undefined;

Expand Down
6 changes: 3 additions & 3 deletions packages/tsc/tests/dts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';
import { proxyCreateProgram } from '@volar/typescript';
import * as vue from '@vue/language-core';
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
import { describe, expect, it } from 'vitest';
import { proxyCreateProgram } from '@volar/typescript';
import * as vue from '@vue/language-core';

const workspace = path.resolve(__dirname, '../../../test-workspace/component-meta');
const normalizePath = (filename: string) => filename.replace(/\\/g, '/');
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createLanguageServicePlugin } from '@volar/typescript/lib/quickstart/createLanguageServicePlugin';
import * as vue from '@vue/language-core';
import type * as ts from 'typescript';
import { proxyLanguageServiceForVue } from './lib/common';
import { startNamedPipeServer } from './lib/server';
import type * as ts from 'typescript';

const windowsPathReg = /\\/g;
const vueCompilerOptions = new WeakMap<ts.server.Project, vue.VueCompilerOptions>();
Expand Down

0 comments on commit 1dad045

Please sign in to comment.