From 1e39ce56436637f8638f7ae4d69e3846c46dce50 Mon Sep 17 00:00:00 2001 From: Omar Tawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Mon, 16 Sep 2024 08:18:05 -0700 Subject: [PATCH] enable slang features unconditionally (#598) --- .../services/initialization/featureFlags.ts | 76 ------------------- .../services/initialization/onInitialize.ts | 24 +----- 2 files changed, 3 insertions(+), 97 deletions(-) delete mode 100644 server/src/services/initialization/featureFlags.ts diff --git a/server/src/services/initialization/featureFlags.ts b/server/src/services/initialization/featureFlags.ts deleted file mode 100644 index 0058f801..00000000 --- a/server/src/services/initialization/featureFlags.ts +++ /dev/null @@ -1,76 +0,0 @@ -import got from "got"; -import crypto from "crypto"; -import { ServerState } from "../../types"; -import { isTestMode } from "../../utils"; - -export interface FeatureFlag { - percent: number; -} - -export interface FeatureFlags { - semanticHighlighting: FeatureFlag; - documentSymbol: FeatureFlag; -} - -const DEFAULT_FLAGS: FeatureFlags = { - semanticHighlighting: { - percent: 0, - }, - documentSymbol: { - percent: 0, - }, -}; - -export async function fetchFeatureFlags( - state: ServerState -): Promise { - state.logger.info("Fetching feature flags"); - - try { - return await got - .get( - "https://raw.githubusercontent.com/NomicFoundation/hardhat-vscode/development/flags.json", - { - timeout: 2000, - } - ) - .json(); - } catch (error) { - state.telemetry.captureException(error); - return DEFAULT_FLAGS; - } -} - -export function isFeatureEnabled( - { logger }: ServerState, - flags: FeatureFlags, - feature: keyof FeatureFlags, - machineId?: string -): boolean { - const flag = flags[feature]; - - if (machineId === undefined) { - logger.info(`MachineId is undefined, turning feature flags off`); - return false; - } - - if (flag === undefined) { - 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); - const digest = machineIdHash.digest("hex").slice(-4); // get last 2 bytes - - // check what percentile the current machineId is in - const numberDigest = parseInt(digest, 16); - const percentile = numberDigest / 65536; - const enabled = percentile < flag.percent; - - return enabled; -} diff --git a/server/src/services/initialization/onInitialize.ts b/server/src/services/initialization/onInitialize.ts index 5d5f4eda..fd1494f8 100644 --- a/server/src/services/initialization/onInitialize.ts +++ b/server/src/services/initialization/onInitialize.ts @@ -9,7 +9,6 @@ import { tokensTypes } from "../semanticHighlight/tokenTypes"; import { isSlangSupported } from "../../parser/slangHelpers"; import { indexWorkspaceFolders } from "./indexWorkspaceFolders"; import { updateAvailableSolcVersions } from "./updateAvailableSolcVersions"; -import { fetchFeatureFlags, isFeatureEnabled } from "./featureFlags"; export const onInitialize = (serverState: ServerState) => { const { logger } = serverState; @@ -43,29 +42,12 @@ export const onInitialize = (serverState: ServerState) => { workspaceFolders, }); - // fetch available solidity versions and feature flags - const [flags, _] = await Promise.all([ - fetchFeatureFlags(serverState), - updateAvailableSolcVersions(serverState), - ]); + await updateAvailableSolcVersions(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", async (transaction) => { await indexWorkspaceFolders( @@ -106,9 +88,9 @@ export const onInitialize = (serverState: ServerState) => { tokenModifiers: [], }, range: false, - full: slangSupported && semanticTokensEnabled, + full: slangSupported, }, - documentSymbolProvider: slangSupported && documentSymbolsEnabled, + documentSymbolProvider: slangSupported, workspace: { workspaceFolders: { supported: false,