Skip to content

Commit

Permalink
replaced imports from 'vscode-languageserver' by imports from 'vscode…
Browse files Browse the repository at this point in the history
…-languageserver-types' in langium's core modules (non-lsp, non-grammar)
  • Loading branch information
sailingKieler committed Feb 13, 2024
1 parent 329217b commit 64ab0b4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/langium/src/default-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DefaultDocumentValidator } from './validation/document-validator.js';
import { ValidationRegistry } from './validation/validation-registry.js';
import { DefaultAstNodeDescriptionProvider, DefaultReferenceDescriptionProvider } from './workspace/ast-descriptions.js';
import { DefaultAstNodeLocator } from './workspace/ast-node-locator.js';
import { DefaultConfigurationProvider } from './workspace/configuration.js';
import { DefaultDocumentBuilder } from './workspace/document-builder.js';
import { DefaultLangiumDocumentFactory, DefaultLangiumDocuments } from './workspace/documents.js';
import { DefaultIndexManager } from './workspace/index-manager.js';
Expand All @@ -33,7 +34,6 @@ import { DefaultCommentProvider } from './documentation/comment-provider.js';
import { LangiumParserErrorMessageProvider } from './parser/langium-parser.js';
import { DefaultAsyncParser } from './parser/async-parser.js';
import { DefaultWorkspaceLock } from './workspace/workspace-lock.js';
import { DefaultConfigurationProvider } from './index.js';

/**
* Context required for creating the default language-specific dependency injection module.
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/documentation/jsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import { Position, Range } from 'vscode-languageserver-types';
import type { CstNode } from '../syntax-tree.js';
import { Position, Range } from 'vscode-languageserver';
import { NEWLINE_REGEXP, escapeRegExp } from '../utils/regexp-utils.js';
import { URI } from '../utils/uri-utils.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { Range } from 'vscode-languageserver';
import type { Range } from 'vscode-languageserver-types';
import type { AstNode, AstReflection, CstNode, GenericAstNode, Mutable, PropertyType, Reference, ReferenceInfo } from '../syntax-tree.js';
import type { Stream, TreeStream } from './stream.js';
import type { LangiumDocument } from '../workspace/documents.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/utils/cst-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { IToken } from '@chevrotain/types';
import type { Range } from 'vscode-languageserver';
import type { Range } from 'vscode-languageserver-types';
import type { CstNode, CompositeCstNode, LeafCstNode } from '../syntax-tree.js';
import type { DocumentSegment } from '../workspace/documents.js';
import type { Stream, TreeStream } from './stream.js';
Expand Down
24 changes: 12 additions & 12 deletions packages/langium/src/validation/document-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
******************************************************************************/

import type { MismatchedTokenException } from 'chevrotain';
import type { Diagnostic } from 'vscode-languageserver';
import type { DiagnosticSeverity, Position, Range, Diagnostic } from 'vscode-languageserver-types';
import type { LanguageMetaData } from '../languages/language-meta-data.js';
import type { ParseResult } from '../parser/langium-parser.js';
import type { LangiumCoreServices } from '../services.js';
import type { AstNode, CstNode } from '../syntax-tree.js';
import type { LangiumDocument } from '../workspace/documents.js';
import type { DiagnosticData, DiagnosticInfo, ValidationAcceptor, ValidationCategory, ValidationRegistry } from './validation-registry.js';
import { DiagnosticSeverity, Position, Range } from 'vscode-languageserver';
import { CancellationToken } from '../utils/cancellation.js';
import { findNodeForKeyword, findNodeForProperty } from '../utils/grammar-utils.js';
import { streamAst } from '../utils/ast-utils.js';
Expand Down Expand Up @@ -100,7 +99,7 @@ export class DefaultDocumentValidator implements DocumentValidator {
protected processLexingErrors(parseResult: ParseResult, diagnostics: Diagnostic[], _options: ValidationOptions): void {
for (const lexerError of parseResult.lexerErrors) {
const diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Error,
severity: toDiagnosticSeverity('error'),
range: {
start: {
line: lexerError.line! - 1,
Expand Down Expand Up @@ -131,20 +130,21 @@ export class DefaultDocumentValidator implements DocumentValidator {
if ('previousToken' in parserError) {
const token = (parserError as MismatchedTokenException).previousToken;
if (!isNaN(token.startOffset)) {
const position = Position.create(token.endLine! - 1, token.endColumn!);
range = Range.create(position, position);
const position: Position = { line: token.endLine! - 1, character: token.endColumn! };
range = { start: position, end: position};
} else {
// No valid prev token. Might be empty document or containing only hidden tokens.
// Point to document start
range = Range.create(0, 0, 0, 0);
const position: Position = { line: 0, character: 0 };
range = { start: position, end: position};
}
}
} else {
range = tokenToRange(parserError.token);
}
if (range) {
const diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Error,
severity: toDiagnosticSeverity('error'),
range,
message: parserError.message,
data: diagnosticData(DocumentValidator.ParsingError),
Expand Down Expand Up @@ -211,7 +211,7 @@ export class DefaultDocumentValidator implements DocumentValidator {
}

export function getDiagnosticRange<N extends AstNode>(info: DiagnosticInfo<N, string>): Range {
if (Range.is(info.range)) {
if (info.range) {
return info.range;
}
let cstNode: CstNode | undefined;
Expand All @@ -233,13 +233,13 @@ export function getDiagnosticRange<N extends AstNode>(info: DiagnosticInfo<N, st
export function toDiagnosticSeverity(severity: 'error' | 'warning' | 'info' | 'hint'): DiagnosticSeverity {
switch (severity) {
case 'error':
return DiagnosticSeverity.Error;
return 1; // according to vscode-languageserver-types/lib/esm/main.js#DiagnosticSeverity.Error
case 'warning':
return DiagnosticSeverity.Warning;
return 2; // according to vscode-languageserver-types/lib/esm/main.js#DiagnosticSeverity.Warning
case 'info':
return DiagnosticSeverity.Information;
return 3; // according to vscode-languageserver-types/lib/esm/main.js#DiagnosticSeverity.Information
case 'hint':
return DiagnosticSeverity.Hint;
return 4; // according to vscode-languageserver-types/lib/esm/main.js#DiagnosticSeverity.Hint
default:
throw new Error('Invalid diagnostic severity: ' + severity);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/validation/validation-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { CodeDescription, DiagnosticRelatedInformation, DiagnosticTag, integer, Range } from 'vscode-languageserver';
import type { CodeDescription, DiagnosticRelatedInformation, DiagnosticTag, integer, Range } from 'vscode-languageserver-types';
import type { CancellationToken } from '../utils/cancellation.js';
import type { LangiumCoreServices } from '../services.js';
import type { AstNode, AstReflection, Properties } from '../syntax-tree.js';
Expand Down

0 comments on commit 64ab0b4

Please sign in to comment.