Skip to content

Commit

Permalink
Merge branch 'master' into socket
Browse files Browse the repository at this point in the history
  • Loading branch information
sockmaster27 committed Aug 1, 2024
2 parents 725d344 + 9b56191 commit 5ef8ee2
Show file tree
Hide file tree
Showing 65 changed files with 1,546 additions and 250 deletions.
6 changes: 6 additions & 0 deletions .vscode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ module.exports = defineConfig({
slow: 30000,

color: true,

allowUncaught: false,
},

env: {
NODE_OPTIONS: '--unhandled-rejections=strict',
},
})
24 changes: 0 additions & 24 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
"vscode": "^1.43.0"
},
"dependencies": {
"lodash": "^4.17.21",
"vscode-languageclient": "^8.0.1"
},
"devDependencies": {
"@types/lodash": "^4.14.191",
"@types/vscode": "^1.74.0"
}
}
12 changes: 5 additions & 7 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { registerFlixReleaseDocumentProvider } from './services/releaseVirtualDo
import { USER_MESSAGE } from './util/userMessages'
import { StatusCode } from './util/statusCodes'

const _ = require('lodash/fp')

export interface LaunchOptions {
shouldUpdateFlix: boolean
}
Expand Down Expand Up @@ -126,7 +124,7 @@ export async function activate(context: vscode.ExtensionContext, launchOptions:
// Utility for safely registering commands
const registeredCommands = await vscode.commands.getCommands(true)
const registerCommand = (command: string, callback: (...args: any[]) => any) => {
if (!_.includes(command, registeredCommands)) {
if (!registeredCommands.includes(command)) {
vscode.commands.registerCommand(command, callback)
}
}
Expand Down Expand Up @@ -224,10 +222,10 @@ async function startSession(
outputChannel.show(true)

const globalStoragePath = context.globalStorageUri.fsPath
const workspaceFolders = _.map(_.flow(_.get('uri'), _.get('fsPath')), vscode.workspace.workspaceFolders)
const workspaceFiles: [string] = _.map(vsCodeUriToUriString, await vscode.workspace.findFiles(FLIX_GLOB_PATTERN))
const workspacePkgs: [string] = _.map(vsCodeUriToUriString, await vscode.workspace.findFiles(FPKG_GLOB_PATTERN))
const workspaceJars: [string] = _.map(vsCodeUriToUriString, await vscode.workspace.findFiles(JAR_GLOB_PATTERN))
const workspaceFolders = vscode.workspace.workspaceFolders?.map(ws => ws.uri.fsPath)
const workspaceFiles = (await vscode.workspace.findFiles(FLIX_GLOB_PATTERN)).map(vsCodeUriToUriString)
const workspacePkgs = (await vscode.workspace.findFiles(FPKG_GLOB_PATTERN)).map(vsCodeUriToUriString)
const workspaceJars = (await vscode.workspace.findFiles(JAR_GLOB_PATTERN)).map(vsCodeUriToUriString)

// Wait until we're sure flix exists
const flixFilename = await ensureFlixExists({
Expand Down
4 changes: 1 addition & 3 deletions client/src/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import ensureFlixExists from './../util/ensureFlixExists'
import { LaunchOptions, defaultLaunchOptions, FLIX_GLOB_PATTERN } from './../extension'
import { USER_MESSAGE } from '../util/userMessages'

const _ = require('lodash/fp')

let flixTerminal: vscode.Terminal | null = null

/**
Expand Down Expand Up @@ -101,7 +99,7 @@ async function handleUnsavedFiles() {
*/
async function getFlixFilename(context: vscode.ExtensionContext, launchOptions: LaunchOptions) {
const globalStoragePath = context.globalStorageUri.fsPath
const workspaceFolders = _.map(_.flow(_.get('uri'), _.get('fsPath')), vscode.workspace.workspaceFolders)
const workspaceFolders = vscode.workspace.workspaceFolders?.map(ws => ws.uri.fsPath)
return await ensureFlixExists({
globalStoragePath,
workspaceFolders,
Expand Down
19 changes: 9 additions & 10 deletions client/src/services/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as zlib from 'zlib'
import * as util from 'util'
import * as path from 'path'
import { strict as nativeAssert } from 'assert'
import * as _ from 'lodash'

const pipeline = util.promisify(stream.pipeline)

Expand Down Expand Up @@ -61,20 +60,20 @@ export async function fetchRelease(
// We skip runtime type checks for simplicity (here we cast from `unknown` to `GithubRelease`)
const release = (await response.json()) as GithubRelease
const flixRelease: FlixRelease = {
url: _.get(release, 'url'),
id: _.get(release, 'id'),
name: _.get(release, 'name'),
description: _.get(release, 'body'),
version: tagToVersion(_.get(release, 'tag_name')),
downloadUrl: _.get(release, 'assets.0.browser_download_url'),
url: release.url,
id: release.id,
name: release.name,
description: release.body,
version: tagToVersion(release.tag_name),
downloadUrl: release.assets[0].browser_download_url,
downloadedAt: Date.now(),
}
return flixRelease
}

function tagToVersion(tagName: string = ''): FlixVersion {
const versionString = tagName[0] === 'v' ? tagName.slice(1) : tagName
const [major, minor, patch] = _.map(_.split(versionString, '.'), _.parseInt)
const [major, minor, patch] = versionString.split('.').map(s => parseInt(s))
return {
major,
minor,
Expand Down Expand Up @@ -117,14 +116,14 @@ export interface FlixRelease {

// We omit declaration of tremendous amount of fields that we are not using here
interface GithubRelease {
url: string
name: string
id: number
body: string
// eslint-disable-next-line camelcase
tag_name: string
published_at: string
assets: Array<{
name: string
// eslint-disable-next-line camelcase
browser_download_url: string
}>
}
Expand Down
12 changes: 5 additions & 7 deletions client/src/services/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import * as vscode from 'vscode'
import { USER_MESSAGE } from '../util/userMessages'

const _ = require('lodash/fp')

// incrementing index to use as keys for resolver maps
let indexCounter = 0

// maintain a list of resolve functions to run when cleaning up
let resolversToCleanUp = {
// idx -> { timer, resolver }
}
let resolversToCleanUp: {
[idx: string]: { timer: NodeJS.Timeout; resolver: () => void }
} = {}

/**
* Ensures the `resolver` is called eventually. Returns a function that should be called if everything works out.
Expand Down Expand Up @@ -58,9 +56,9 @@ export function ensureCleanupEventually(resolver: () => void, timeout = 180) {
* Empty the map of resolvers, clearing their timeouts and calling each resolver.
*/
export function callResolversAndEmptyList() {
_.each(({ timer, resolver }) => {
for (const { timer, resolver } of Object.values(resolversToCleanUp)) {
clearTimeout(timer)
resolver()
}, resolversToCleanUp)
}
resolversToCleanUp = {}
}
14 changes: 0 additions & 14 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
"url": "https://github.com/flix/vscode-flix"
},
"dependencies": {
"lodash": "^4.17.21",
"portfinder": "^1.0.32",
"reconnecting-websocket": "^4.4.0",
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.8",
"ws": "^8.17.1"
},
"devDependencies": {
"@types/lodash": "^4.14.191",
"@types/ws": "^8.5.10"
},
"scripts": {}
Expand Down
13 changes: 6 additions & 7 deletions server/src/engine/flix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { sendNotification } from '../server'
import javaVersion from '../util/javaVersion'
import { ChildProcess, spawn } from 'child_process'
import { getPortPromise } from 'portfinder'
import * as _ from 'lodash'

import * as jobs from './jobs'
import * as queue from './queue'
Expand Down Expand Up @@ -62,11 +61,11 @@ export function getFlixFilename() {
}

export function getExtensionVersion() {
return _.get(startEngineInput, 'extensionVersion', '(unknown version)')
return startEngineInput.extensionVersion ?? '(unknown version)'
}

export function updateUserConfiguration(userConfiguration: UserConfiguration) {
_.set(userConfiguration, 'userConfiguration', startEngineInput)
startEngineInput.userConfiguration = userConfiguration
}

export async function start(input: StartEngineInput) {
Expand All @@ -75,7 +74,7 @@ export async function start(input: StartEngineInput) {
}

// copy input to local var for later use
startEngineInput = _.clone(input)
startEngineInput = { ...input }

const { flixFilename, extensionPath, workspaceFiles, workspacePkgs, workspaceJars } = input

Expand Down Expand Up @@ -136,9 +135,9 @@ export async function start(input: StartEngineInput) {
uri: webSocketUrl,
onOpen: function handleOpen() {
flixRunning = true
const addUriJobs = _.map(workspaceFiles, uri => ({ uri, request: jobs.Request.apiAddUri }))
const addPkgJobs = _.map(workspacePkgs, uri => ({ uri, request: jobs.Request.apiAddPkg }))
const addJarJobs = _.map(workspaceJars, uri => ({ uri, request: jobs.Request.apiAddJar }))
const addUriJobs = workspaceFiles.map(uri => ({ uri, request: jobs.Request.apiAddUri }))
const addPkgJobs = workspacePkgs.map(uri => ({ uri, request: jobs.Request.apiAddPkg }))
const addJarJobs = workspaceJars.map(uri => ({ uri, request: jobs.Request.apiAddJar }))
const Jobs: jobs.Job[] = [...addUriJobs, ...addPkgJobs, ...addJarJobs]
queue.initialiseQueues(Jobs)
handleVersion()
Expand Down
19 changes: 9 additions & 10 deletions server/src/engine/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { fileURLToPath } from 'url'
import { sendNotification } from '../server'
import { USER_MESSAGE } from '../util/userMessages'

const _ = require('lodash/fp')
const fs = require('fs')

let jobCounter = 0
Expand Down Expand Up @@ -53,13 +52,13 @@ function jobToEnqueuedJob(job: jobs.Job) {
}

function emptyWaitingForPriorityQueue() {
const values = _.values(waitingForPriorityQueue)
const values = Object.values(waitingForPriorityQueue)
waitingForPriorityQueue = {}
return values
}

function handleEnqueue() {
if (_.isEmpty(waitingForPriorityQueue)) {
if (Object.values(waitingForPriorityQueue).length === 0) {
return
}
priorityQueue.push(...emptyWaitingForPriorityQueue())
Expand All @@ -82,7 +81,7 @@ export function enqueue(job: jobs.Job): jobs.EnqueuedJob {
if (job.request === jobs.Request.lspCheck) {
// there's a special rule for lsp/check:
// there can only be one and it has to be in the beginning
taskQueue = _.reject({ request: jobs.Request.lspCheck }, taskQueue)
taskQueue = taskQueue.filter(({ request }) => request !== jobs.Request.lspCheck)
taskQueue.unshift(enqueuedJob)
} else {
taskQueue.push(enqueuedJob)
Expand Down Expand Up @@ -116,18 +115,18 @@ export function initialiseQueues(jobs: jobs.Job[]) {
* Otherwise take the first item off taskQueue.
*/
function dequeue() {
if (_.isEmpty(priorityQueue)) {
if (_.isEmpty(taskQueue)) {
if (priorityQueue.length === 0) {
if (taskQueue.length === 0) {
return undefined
}
const first = _.first(taskQueue)
const first = taskQueue[0]
taskQueue.shift()
return first
} else {
// priorityQueue has items
const first = _.first(priorityQueue)
const first = priorityQueue[0]
priorityQueue.shift()
if (_.isEmpty(priorityQueue)) {
if (priorityQueue.length === 0) {
enqueue({
request: jobs.Request.lspCheck,
})
Expand Down Expand Up @@ -156,7 +155,7 @@ export async function processQueue() {
// VSCode might ask us to do things before we're up and running - wait for next processQueue call
return
}
const job: jobs.EnqueuedJob = dequeue()
const job = dequeue()
if (job) {
try {
if (job.request === jobs.Request.apiAddUri && !job.src) {
Expand Down
Loading

0 comments on commit 5ef8ee2

Please sign in to comment.