Giter Club home page Giter Club logo

volar.js's People

Contributors

blake-newman avatar fuzzyma avatar ghiscoding avatar johnsoncodehk avatar princesseuh avatar skywalker512 avatar the-mikedavis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

volar.js's Issues

[Language Server] Performance pitfalls of recursively searching for tsconfig.json

In the following line, the language server attempts to search for all tsconfigs from the workspace root directory. If the user attempts to start vscode from the system root directory and opens a vue file, this could lead to performance issues for the language server searching through the entire file system for tsconfigs.

const rootTsConfigs = new Set(sys?.readDirectory(uriToFileName(context.rootUri.toString()), rootTsConfigNames, undefined, ['**/*']).map(fileName => fileName.replace(/\\/g, '/') as path.PosixPath));

A better approach would be to attempt to search up for the tsconfig for each request.

Add source.sortImports support for .vue files in Volar

Preamble

I think this issue needs to be in language-tools, but that repo has limited issue reporting to existing contributors, so I can't post this there. If it does need to be moved, I would appreciate a contributor adding it over there. Thank you in advance!

Request

I use VS Code for Vue development with the Volar plugins. In my VS Code config I used to use source.organizeImports in editor.codeActionsOnSave but it deletes unused imports which can break an application. I read that VS Code v1.57 added the source.sortImports action for javascript and typescript files. However, this action has no effect on .vue files.

Please add source.sortImports support for .vue files so I can automatically organize my inputs in a non-destructive manner.

Thank you!

Create available commands for IDEs other than VSCode

Currently we have factory code for building commands in the following code, but it only works for VSCode (seems to work for coc too). We should judge the IDE of the language client to return the command format actually supported by the current IDE.

commands: {
rename: {
create(uri, position) {
const source = toSourceLocation(uri, position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename);
if (!source) {
return;
}
return vscode.Command.create(
'',
'editor.action.rename',
source.uri,
source.position,
);
},
is(command) {
return command.command === 'editor.action.rename';
},
},
showReferences: {
create(uri, position, locations) {
const source = toSourceLocation(uri, position);
if (!source) {
return;
}
const sourceReferences: vscode.Location[] = [];
for (const reference of locations) {
if (context.documents.isVirtualFileUri(reference.uri)) {
for (const [_, map] of context.documents.getMapsByVirtualFileUri(reference.uri)) {
const range = map.toSourceRange(reference.range);
if (range) {
sourceReferences.push({ uri: map.sourceFileDocument.uri, range });
}
}
}
else {
sourceReferences.push(reference);
}
}
return vscode.Command.create(
locations.length === 1 ? '1 reference' : `${locations.length} references`,
'editor.action.showReferences',
source.uri,
source.position,
sourceReferences,
);
},
is(command) {
return command.command === 'editor.action.showReferences';
},
},
setSelection: {
create(position: vscode.Position) {
return vscode.Command.create(
'',
'setSelection',
{
selection: {
selectionStartLineNumber: position.line + 1,
positionLineNumber: position.line + 1,
selectionStartColumn: position.character + 1,
positionColumn: position.character + 1,
},
},
);
},
is(command) {
return command.command === 'setSelection';
}
},

Custom SFC blocks

Hello there ! Thanks for making Volar, it is really awesome.

I want to implement server blocks for Nuxt nuxt/nuxt#20802
The SFC is going to look like this.

Under the hood, this entire block content would be removed, and processed separately by Nuxt. It wouldn't be present in the component itself, it's essentially isolated from blocks.

Adding lang="ts" make the color syntax work, but I want all the Typescript features to work, such as following the correct tsconfig and also typechecking.
I've considered using a <script server> tag too, but it seems to be easier with a custom name.
What needs to happen with Volar to make something like this work ? I would appreciate if you could point me in the right direction.
Thanks !

Plugin API v1

Before:

export interface LanguageServicePluginInstance {
rules?: {
onAny?(context: RuleContext): NotNullableResult<RuleContext>;
onFormat?(context: RuleContext): NotNullableResult<RuleContext>;
onSyntax?(context: RuleContext): NotNullableResult<RuleContext>;
onSemantic?(context: RuleContext): NotNullableResult<RuleContext>;
};
validation?: {
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
onDeclaration?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
};
doHover?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Hover>,
findImplementations?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
findReferences?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Location[]>;
findFileReferences?(document: TextDocument): NullableResult<vscode.Location[]>;
findDocumentHighlights?(document: TextDocument, position: vscode.Position): NullableResult<vscode.DocumentHighlight[]>;
findDocumentLinks?(document: TextDocument): NullableResult<vscode.DocumentLink[]>;
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.DocumentSymbol[]>;
findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>;
findWorkspaceSymbols?(query: string): NullableResult<vscode.WorkspaceSymbol[]>;
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
getFoldingRanges?(document: TextDocument): NullableResult<vscode.FoldingRange[]>;
getSelectionRanges?(document: TextDocument, positions: vscode.Position[]): NullableResult<vscode.SelectionRange[]>;
getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>;
format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
formatOnType?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
getIndentSensitiveLines?(document: TextDocument): NullableResult<number[]>;
definition?: {
on?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
onType?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
};
complete?: {
triggerCharacters?: string[],
isAdditional?: boolean,
on?(document: TextDocument, position: vscode.Position, context?: vscode.CompletionContext): NullableResult<vscode.CompletionList>,
resolve?(item: vscode.CompletionItem): NotNullableResult<vscode.CompletionItem>,
};
rename?: {
prepare?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Range | vscode.ResponseError<void>>;
on?(document: TextDocument, position: vscode.Position, newName: string): NullableResult<vscode.WorkspaceEdit>;
};
codeAction?: {
on?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext): NullableResult<vscode.CodeAction[]>;
resolve?(codeAction: vscode.CodeAction): NotNullableResult<vscode.CodeAction>;
};
codeLens?: {
on?(document: TextDocument): NullableResult<vscode.CodeLens[]>;
resolve?(codeLens: vscode.CodeLens): NotNullableResult<vscode.CodeLens>;
};
referencesCodeLens?: {
on?(document: TextDocument): NullableResult<vscode.Location[]>;
resolve?(document: TextDocument, location: vscode.Location, references: vscode.Location[]): NotNullableResult<vscode.Location[]>;
};
callHierarchy?: {
prepare(document: TextDocument, position: vscode.Position): NullableResult<vscode.CallHierarchyItem[]>;
onIncomingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyIncomingCall[]>;
onOutgoingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyOutgoingCall[]>;
};
inlayHints?: {
on?(document: TextDocument, range: vscode.Range): NullableResult<vscode.InlayHint[]>,
// TODO: resolve
};
// html
findLinkedEditingRanges?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LinkedEditingRanges>;
doAutoInsert?(document: TextDocument, position: vscode.Position, context: {
lastChange: {
range: vscode.Range;
rangeOffset: number;
rangeLength: number;
text: string;
};
}): NullableResult<string | vscode.TextEdit>;
/**
* TODO: only support to doCompleteResolve for now
*/
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
}

v1:

export interface LanguageServicePluginInstance {
isAdditionalCompletion?: boolean; // volar specific
triggerCharacters?: string[];
signatureHelpTriggerCharacters?: string[];
signatureHelpRetriggerCharacters?: string[];
autoFormatTriggerCharacters?: string[];
prepareRename?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Range | vscode.ResponseError<void>>;
provideHover?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Hover>,
provideDocumentSymbols?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.DocumentSymbol[]>;
provideDocumentHighlights?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.DocumentHighlight[]>;
provideLinkedEditingRanges?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LinkedEditingRanges>;
provideDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LocationLink[]>;
provideTypeDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LocationLink[]>;
provideImplementation?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LocationLink[]>;
provideCodeLenses?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.CodeLens[]>;
provideCodeActions?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): NullableResult<vscode.CodeAction[]>;
provideDocumentFormattingEdits?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions, token: vscode.CancellationToken): NullableResult<vscode.TextEdit[]>;
provideOnTypeFormattingEdits?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions, token: vscode.CancellationToken): NullableResult<vscode.TextEdit[]>;
provideLinks?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.DocumentLink[]>;
provideCompletionItems?(document: TextDocument, position: vscode.Position, context: vscode.CompletionContext, token: vscode.CancellationToken): NullableResult<vscode.CompletionList>,
provideDocumentColors?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.ColorInformation[]>;
provideColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range, token: vscode.CancellationToken): NullableResult<vscode.ColorPresentation[]>;
provideFoldingRanges?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.FoldingRange[]>;
provideSignatureHelp?(document: TextDocument, position: vscode.Position, context: vscode.SignatureHelpContext, token: vscode.CancellationToken): NullableResult<vscode.SignatureHelp>;
provideRenameEdits?(document: TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceEdit>;
provideReferences?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Location[]>;
provideSelectionRanges?(document: TextDocument, positions: vscode.Position[], token: vscode.CancellationToken): NullableResult<vscode.SelectionRange[]>;
provideInlayHints?(document: TextDocument, range: vscode.Range, token: vscode.CancellationToken): NullableResult<vscode.InlayHint[]>,
provideCallHierarchyItems(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.CallHierarchyItem[]>;
provideCallHierarchyIncomingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyIncomingCall[]>;
provideCallHierarchyOutgoingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyOutgoingCall[]>;
provideDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken): NullableResult<SemanticToken[]>;
provideWorkspaceSymbols?(query: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceSymbol[]>;
provideSyntacticDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Diagnostic[]>;
provideSemanticDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Diagnostic[]>;
provideFileReferences?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Location[]>; // volar specific
provideReferencesCodeLenses?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Location[]>; // volar specific
provideAutoInsertionEdit?(document: TextDocument, position: vscode.Position, context: AutoInsertionContext, token: vscode.CancellationToken): NullableResult<string | vscode.TextEdit>; // volar specific
provideFileRenameEdits?(oldUri: string, newUri: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceEdit>; // volar specific
provideFormattingIndentSensitiveLines?(document: TextDocument, token: vscode.CancellationToken): NullableResult<number[]>; // volar specific
resolveCodeLens?(codeLens: vscode.CodeLens, token: vscode.CancellationToken): Result<vscode.CodeLens>;
resolveCodeAction?(codeAction: vscode.CodeAction, token: vscode.CancellationToken): Result<vscode.CodeAction>;
resolveCompletionItem?(item: vscode.CompletionItem, token: vscode.CancellationToken): Result<vscode.CompletionItem>,
resolveReferencesCodeLens?(document: TextDocument, location: vscode.Location, references: vscode.Location[], token: vscode.CancellationToken): Result<vscode.Location[]>; // volar specific
resolveRuleContext?(context: RuleContext, ruleType: 'format' | 'syntax' | 'semantic'): Result<RuleContext>; // volar specific
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined; // volar specific, only support in resolveCompletionItem for now
// resolveLink
// resolveInlayHint
}

`volar.config.js` does not load on Windows

volar.config.js has no effect on Windows because the language server fails to resolve the file path.

This happens because of the path property on the URI class from vscode-uri. On windows it returns /c:/path instead of c:/path.

The fix is to use fsPath instead of path when calling loadConfig

Deprecate `@volar/shared`

We've pretty much disassembled the shared module's functions down to the actual used packages, and we'll be able to remove it.

"Save as..." in VSCode often triggers "Virtual script not found" error

Obviously there's no way to repro this in a repo, because this is an extension bug in VSCode, but on more than one occasion, if I'm working with a Vue SFC (in TypeScript), and I "Save as..." another file in the same folder, the script tag will say: Virtual script not found, may missing <script lang="ts"> / "allowJs": true / jsconfig.json

allowJs is enabled and was working just fine in tsconfig.json. Creating a jsconfig.json of course has no effect, because it's TypeScript (but I tried anyway). It happens only when duplicating a file. Restarting Volar is the only current fix.

volar fails to start due to a syntax error

Hello,

Using NeoVim I have installed the volar LSP via Mason.
Now, when I edit a .vue file, the volar LSP client immediately crashes with exit code 1 and signal 0.

This is the complete output in lsp.log (I will split it in multiple lines for readability):

[START][2023-04-16 09:06:32] LSP logging initiated
[ERROR][2023-04-16 09:06:32] .../vim/lsp/rpc.lua:734	"rpc"	"vue-language-server"	"stderr"
"/home/vincent/.local/share/nvim/mason/packages/vue-language-server/node_modules/@volar/
  vue-language-server/node_modules/@vscode/l10n/dist/main.js:846
throw new Error(e.responseText ?? (0, import_request_light.getErrorStatusDescription)(e.status) ?? e.toString());

SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /home/vincent/.local/share/nvim/mason/packages/vue-language-server/node_modules/@volar/
  vue-language-server/node_modules/vscode-html-languageservice/lib/umd/parser/htmlScanner.js:17:18
at /home/vincent/.local/share/nvim/mason/packages/vue-language-server/node_modules/@volar/
  vue-language-server/node_modules/vscode-html-languageservice/lib/umd/parser/htmlScanner.js:7:17
at Object.<anonymous> (/home/vincent/.local/share/nvim/mason/packages/vue-language-server/
  node_modules/@volar/vue-language-server/node_modules/vscode-html-languageservice/lib/umd/parser/
  htmlScanner.js:13:3)"

Support remove all unused imports in Vue.js SFC?

Now, if the project supports ESlint, we can delete all unused imports using the VSCode ESlint quick fix. However, I believe it would take less time if we could accomplish this using a command.

Quick fix

image

Command

image

Infinite recursion / stack overflow in getProgram Proxy

See screenshot. getProgram is getting called infinitely recursively. This is happening when using vite-plugin-checker 0.5.6 with vue-tsc 1.1.7 and typescript 4.9.5, although I don't think its anything that vite-plugin-checker is doing wrong.

If it helps, the stack frame before the one selected in my screenshot, resolveNamesWithLocalCache, is trying to call program.getResolvedProjectReferenceToRedirect('C:/my/project/__inferred type names__.ts') on every single stack frame that that function is repeated.

image

Integration with CodeMirror

We have now completed the Monaco integration and when I checked @vue/repl I noticed it also uses another web code editor called CodeMirror, I was just considering whether it also needs LSP support.

The closest solution at the moment is codemirror-languageserver maintained by @hjr265.

But perhaps a compatibility package between Monaco worker and CodeMirror editor would be a better approach?

For now, I will keep this issue open but I may not do the work because I am not even sure if CodeMirror is still being used or maintained by the community.

Use `@volar/kit` to linting this repo

Rules:

  • Service needs to annotate the return type
  • Use import type for typescript/lib/tsserverlibrary
  • import typescript/lib/tsserverlibrary instead of typescript

The Vue Semantic Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

Bug

Error: Debug Failure. False expression: y:/mapped_network_drive/path/to/project/node_modules/vue/dist/vue.d.ts linked to nonexistent file //server/linux/path/to/project/node_modules/vue/dist/vue.d.ts

Project Info:

Additional Infomation

[@volar-plugins/typescript] sourceFile not found file:///y%3A/path/to/project/app.vue.js
c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:39898

Volar intellisense takeover mode does not resolve external workspaces/packages (monorepo)

Volar is not handling resolving external workspaces/packages within monorepo.

Reproduction: https://github.com/blake-newman/vue-tsc-import-resolution

takeover mode: off

When takeover mode is off it is able to auto import the modules/dependencies from external workspaces/packages

  • Enable the built-in TypeScript Extension
    • Run Extensions: Show Built-in Extensions from VSCode's command palette
    • Find TypeScript and JavaScript Language Features, right click and select Enable (Workspace)
  • Reload the VSCode window by running Developer: Reload Window from the command palette.
  • Within ./packages/main/src/index.ts try to use isFalse function from b package.
    • The exported function is found in intelisense and choosing that will auto import the dependency.

Screenshot 2023-03-16 at 09 01 37

takeover mode: on

When takeover mode is on it is unable to auto import modules/dependencies from external workspaces/packages

  • Enable the built-in TypeScript Extension
    • Run Extensions: Show Built-in Extensions from VSCode's command palette
    • Find TypeScript and JavaScript Language Features, right click and select Disable (Workspace)
  • Reload the VSCode window by running Developer: Reload Window from the command palette.
  • Within ./packages/main/src/index.ts try to use isFalse function from b package.
    • The exported function is not found in intelisense

Screenshot 2023-03-16 at 08 58 19

Having issues with Vue Doc Examples

<script setup lang="ts">
defineProps(['modelValue'])
defineEmits(['update:modelValue'])
</script>

<template>
  <input :model-value="modelValue" @input="$emit('update:modelValue', $event.target?.value)">
</template>

for a component as simple as this, I am getting type errors from Volar (im in takeover mode and forced TS version to 4.9.5) saying that "Property value does not exist on type 'EventType'"

also using nuxt 3.3.2 if that matters

tried looking around and finding other solutions as well, any help is greatly appreciated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.