Socket
Socket
Sign inDemoInstall

@volar/language-server

Package Overview
Dependencies
Maintainers
1
Versions
232
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@volar/language-server


Version published
Weekly downloads
214K
increased by1.5%
Maintainers
1
Weekly downloads
 
Created

What is @volar/language-server?

@volar/language-server is a language server implementation for Vue.js, providing rich language features such as auto-completion, diagnostics, and more. It is designed to work with the Language Server Protocol (LSP) to enhance the development experience in editors like VSCode.

What are @volar/language-server's main functionalities?

Auto-completion

This code sets up a basic language server with auto-completion capabilities. When the user types, the server will suggest 'HelloWorld' as a completion item.

const { createConnection, TextDocuments } = require('@volar/language-server');
const connection = createConnection();
const documents = new TextDocuments();

connection.onInitialize(() => {
  return {
    capabilities: {
      textDocumentSync: documents.syncKind,
      completionProvider: {
        resolveProvider: true
      }
    }
  };
});

connection.onCompletion((textDocumentPosition) => {
  return [
    {
      label: 'HelloWorld',
      kind: 1,
      data: 1
    }
  ];
});

documents.listen(connection);
connection.listen();

Diagnostics

This code sets up a language server that provides diagnostics. If the text 'error' is found in the document, it will report a diagnostic error.

const { createConnection, TextDocuments, Diagnostic, DiagnosticSeverity } = require('@volar/language-server');
const connection = createConnection();
const documents = new TextDocuments();

connection.onInitialize(() => {
  return {
    capabilities: {
      textDocumentSync: documents.syncKind
    }
  };
});

documents.onDidChangeContent((change) => {
  const diagnostics = [];
  const text = change.document.getText();
  if (text.includes('error')) {
    diagnostics.push({
      severity: DiagnosticSeverity.Error,
      range: {
        start: { line: 0, character: 0 },
        end: { line: 0, character: 5 }
      },
      message: 'Found an error keyword',
      source: 'ex'
    });
  }
  connection.sendDiagnostics({ uri: change.document.uri, diagnostics });
});

documents.listen(connection);
connection.listen();

Other packages similar to @volar/language-server

FAQs

Package last updated on 23 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc