From bcc6c11589dd8b789820d80442a7a03065a01013 Mon Sep 17 00:00:00 2001 From: Armando Andini Date: Sat, 11 Nov 2023 12:37:56 -0300 Subject: [PATCH] fix linter --- client/scripts/bundle.js | 20 +++++----- .../services/documentSymbol/SymbolVisitor.ts | 1 - .../documentSymbol/onDocumentSymbol.ts | 9 ----- .../services/initialization/featureFlags.ts | 5 +++ .../services/initialization/onInitialize.ts | 37 ++++++++++++------- .../ContractDefinitionHighlighter.ts | 3 +- .../highlighters/CustomTypeHighlighter.ts | 3 +- .../EventDefinitionHighlighter.ts | 3 +- .../highlighters/EventEmissionHighlighter.ts | 3 +- .../highlighters/FunctionCallHighlighter.ts | 3 +- .../FunctionDefinitionHighlighter.ts | 3 +- .../InterfaceDefinitionHighlighter.ts | 3 +- .../highlighters/KeywordHighlighter.ts | 3 +- .../highlighters/NumberHighlighter.ts | 3 +- .../highlighters/StringHighlighter.ts | 3 +- .../StructDefinitionHighlighter.ts | 3 +- .../semanticHighlight/onSemanticTokensFull.ts | 2 +- server/src/telemetry/SentryServerTelemetry.ts | 2 - 18 files changed, 50 insertions(+), 59 deletions(-) diff --git a/client/scripts/bundle.js b/client/scripts/bundle.js index 2df7e7fc..d7cc443c 100755 --- a/client/scripts/bundle.js +++ b/client/scripts/bundle.js @@ -200,16 +200,16 @@ async function main() { "@nomicfoundation/solidity-analyzer-linux-x64-musl": "0.1.1", "@nomicfoundation/solidity-analyzer-freebsd-x64": "0.1.1", - "@nomicfoundation/slang": "0.4.0", - "@nomicfoundation/slang-darwin-arm64": "0.4.0", - "@nomicfoundation/slang-win32-arm64-msvc": "0.4.0", - "@nomicfoundation/slang-linux-arm64-gnu": "0.4.0", - "@nomicfoundation/slang-linux-arm64-musl": "0.4.0", - "@nomicfoundation/slang-win32-ia32-msvc": "0.4.0", - "@nomicfoundation/slang-darwin-x64": "0.4.0", - "@nomicfoundation/slang-win32-x64-msvc": "0.4.0", - "@nomicfoundation/slang-linux-x64-gnu": "0.4.0", - "@nomicfoundation/slang-linux-x64-musl": "0.4.0", + "@nomicfoundation/slang": "0.10.1", + "@nomicfoundation/slang-darwin-arm64": "0.10.1", + "@nomicfoundation/slang-win32-arm64-msvc": "0.10.1", + "@nomicfoundation/slang-linux-arm64-gnu": "0.10.1", + "@nomicfoundation/slang-linux-arm64-musl": "0.10.1", + "@nomicfoundation/slang-win32-ia32-msvc": "0.10.1", + "@nomicfoundation/slang-darwin-x64": "0.10.1", + "@nomicfoundation/slang-win32-x64-msvc": "0.10.1", + "@nomicfoundation/slang-linux-x64-gnu": "0.10.1", + "@nomicfoundation/slang-linux-x64-musl": "0.10.1", }, }) ); diff --git a/server/src/services/documentSymbol/SymbolVisitor.ts b/server/src/services/documentSymbol/SymbolVisitor.ts index 8461b354..8965cc22 100644 --- a/server/src/services/documentSymbol/SymbolVisitor.ts +++ b/server/src/services/documentSymbol/SymbolVisitor.ts @@ -12,7 +12,6 @@ export abstract class SymbolVisitor { public abstract ruleKind: RuleKind; public abstract symbolKind: SymbolKind; public abstract nameTokenKind: TokenKind; - public nameTokenSkips = 0; constructor( public document: TextDocument, diff --git a/server/src/services/documentSymbol/onDocumentSymbol.ts b/server/src/services/documentSymbol/onDocumentSymbol.ts index 4621e143..7f2fde40 100644 --- a/server/src/services/documentSymbol/onDocumentSymbol.ts +++ b/server/src/services/documentSymbol/onDocumentSymbol.ts @@ -79,15 +79,6 @@ export function onDocumentSymbol(serverState: ServerState) { throw new Error(`Slang parsing error: ${strings.join("")}`); } - // const kursor: Cursor = parseTree.cursor.clone(); - // do { - // console.log( - // `${" ".repeat(kursor.pathRuleNodes.length)}${kursor.node.kind}(${ - // ["R", "T"][kursor.node.type] - // }): ${kursor.node?.text ?? ""}` - // ); - // } while (kursor.goToNext()); - const builder = new SymbolTreeBuilder(); const visitors: SymbolVisitor[] = [ diff --git a/server/src/services/initialization/featureFlags.ts b/server/src/services/initialization/featureFlags.ts index e264074f..3d7a7b1c 100644 --- a/server/src/services/initialization/featureFlags.ts +++ b/server/src/services/initialization/featureFlags.ts @@ -1,6 +1,7 @@ import got from "got"; import crypto from "crypto"; import { ServerState } from "../../types"; +import { isTestMode } from "../../utils"; export interface FeatureFlag { percent: number; @@ -57,6 +58,10 @@ export function isFeatureEnabled( throw new Error(`Feature flag not found: ${feature}`); } + if (isTestMode()) { + return true; + } + // hash the machineId to get an evenly distributed value const machineIdHash = crypto.createHash("md5"); machineIdHash.update(machineId); diff --git a/server/src/services/initialization/onInitialize.ts b/server/src/services/initialization/onInitialize.ts index 342ed876..62413bd2 100644 --- a/server/src/services/initialization/onInitialize.ts +++ b/server/src/services/initialization/onInitialize.ts @@ -52,6 +52,21 @@ export const onInitialize = (serverState: ServerState) => { logger.info("Language server ready"); + const slangSupported = isSlangSupported(); + + const semanticTokensEnabled = isFeatureEnabled( + serverState, + flags, + "semanticHighlighting", + machineId + ); + + const documentSymbolsEnabled = isFeatureEnabled( + serverState, + flags, + "documentSymbol", + machineId + ); // Index and analysis await serverState.telemetry.trackTiming( "indexing", @@ -65,11 +80,14 @@ export const onInitialize = (serverState: ServerState) => { return { status: "ok", result: null }; }, - { platform: getPlatform() } + { + platform: getPlatform(), + slangSupported, + semanticTokensEnabled, + documentSymbolsEnabled, + } ); - const slangSupported = isSlangSupported(); - // Build and return InitializeResult const result: InitializeResult = { serverInfo: { @@ -98,18 +116,9 @@ export const onInitialize = (serverState: ServerState) => { tokenModifiers: [], }, range: false, - full: - slangSupported && - isFeatureEnabled( - serverState, - flags, - "semanticHighlighting", - machineId - ), + full: slangSupported && semanticTokensEnabled, }, - documentSymbolProvider: - slangSupported && - isFeatureEnabled(serverState, flags, "documentSymbol", machineId), + documentSymbolProvider: slangSupported && documentSymbolsEnabled, workspace: { workspaceFolders: { supported: false, diff --git a/server/src/services/semanticHighlight/highlighters/ContractDefinitionHighlighter.ts b/server/src/services/semanticHighlight/highlighters/ContractDefinitionHighlighter.ts index 60e1d7ad..a0449c91 100644 --- a/server/src/services/semanticHighlight/highlighters/ContractDefinitionHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/ContractDefinitionHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/CustomTypeHighlighter.ts b/server/src/services/semanticHighlight/highlighters/CustomTypeHighlighter.ts index 9c001779..7336ec19 100644 --- a/server/src/services/semanticHighlight/highlighters/CustomTypeHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/CustomTypeHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/EventDefinitionHighlighter.ts b/server/src/services/semanticHighlight/highlighters/EventDefinitionHighlighter.ts index ac26961e..beeda201 100644 --- a/server/src/services/semanticHighlight/highlighters/EventDefinitionHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/EventDefinitionHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/EventEmissionHighlighter.ts b/server/src/services/semanticHighlight/highlighters/EventEmissionHighlighter.ts index e3d37c31..96bc1611 100644 --- a/server/src/services/semanticHighlight/highlighters/EventEmissionHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/EventEmissionHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/FunctionCallHighlighter.ts b/server/src/services/semanticHighlight/highlighters/FunctionCallHighlighter.ts index b2d74ed7..52b8b7f9 100644 --- a/server/src/services/semanticHighlight/highlighters/FunctionCallHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/FunctionCallHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/FunctionDefinitionHighlighter.ts b/server/src/services/semanticHighlight/highlighters/FunctionDefinitionHighlighter.ts index 3c92b430..bce240a5 100644 --- a/server/src/services/semanticHighlight/highlighters/FunctionDefinitionHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/FunctionDefinitionHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/InterfaceDefinitionHighlighter.ts b/server/src/services/semanticHighlight/highlighters/InterfaceDefinitionHighlighter.ts index 5b425951..3c2e12d8 100644 --- a/server/src/services/semanticHighlight/highlighters/InterfaceDefinitionHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/InterfaceDefinitionHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/KeywordHighlighter.ts b/server/src/services/semanticHighlight/highlighters/KeywordHighlighter.ts index f63ebf83..e44e40c4 100644 --- a/server/src/services/semanticHighlight/highlighters/KeywordHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/KeywordHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; import { TokenKind } from "@nomicfoundation/slang/kinds"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; -import { Cursor } from "@nomicfoundation/slang/cursor"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/NumberHighlighter.ts b/server/src/services/semanticHighlight/highlighters/NumberHighlighter.ts index 0be44882..09852474 100644 --- a/server/src/services/semanticHighlight/highlighters/NumberHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/NumberHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; import { TokenKind } from "@nomicfoundation/slang/kinds"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; -import { Cursor } from "@nomicfoundation/slang/cursor"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/StringHighlighter.ts b/server/src/services/semanticHighlight/highlighters/StringHighlighter.ts index 4bf3ec2a..9937e472 100644 --- a/server/src/services/semanticHighlight/highlighters/StringHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/StringHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; import { TokenKind } from "@nomicfoundation/slang/kinds"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; -import { Cursor } from "@nomicfoundation/slang/cursor"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/highlighters/StructDefinitionHighlighter.ts b/server/src/services/semanticHighlight/highlighters/StructDefinitionHighlighter.ts index dcb205da..1a31047a 100644 --- a/server/src/services/semanticHighlight/highlighters/StructDefinitionHighlighter.ts +++ b/server/src/services/semanticHighlight/highlighters/StructDefinitionHighlighter.ts @@ -1,7 +1,6 @@ import { SemanticTokenTypes } from "vscode-languageserver-protocol"; -import { NodeType, TokenNode } from "@nomicfoundation/slang/cst"; +import { NodeType } from "@nomicfoundation/slang/cst"; import { RuleKind, TokenKind } from "@nomicfoundation/slang/kinds"; -import { Cursor } from "@nomicfoundation/slang/cursor"; import { HighlightVisitor } from "../HighlightVisitor"; import { SlangNodeWrapper } from "../../../parser/slangHelpers"; diff --git a/server/src/services/semanticHighlight/onSemanticTokensFull.ts b/server/src/services/semanticHighlight/onSemanticTokensFull.ts index 46b1ec9b..943bf6e8 100644 --- a/server/src/services/semanticHighlight/onSemanticTokensFull.ts +++ b/server/src/services/semanticHighlight/onSemanticTokensFull.ts @@ -145,7 +145,7 @@ export function onSemanticTokensFull(serverState: ServerState) { return { status: "ok", result: { data: builder.getTokenData() } }; } catch (error) { - logger.error(error); + logger.error(`Slang parsing error: ${error}`); return { status: "internal_error", result: emptyResponse }; } }) || emptyResponse diff --git a/server/src/telemetry/SentryServerTelemetry.ts b/server/src/telemetry/SentryServerTelemetry.ts index 20e2a4d6..34917058 100644 --- a/server/src/telemetry/SentryServerTelemetry.ts +++ b/server/src/telemetry/SentryServerTelemetry.ts @@ -131,8 +131,6 @@ export class SentryServerTelemetry implements Telemetry { return null; } finally { transaction.finish(); - // const elapsed = transaction.endTimestamp! - transaction.startTimestamp; - // console.log(`${taskName}: ${elapsed * 1000} ms`); } }