Skip to content

Commit

Permalink
Merge pull request #57 from Code-Inspect/52-the-extension-should-repo…
Browse files Browse the repository at this point in the history
…rt-the-flowr-version-in-use

Update the status bar to report additional information
  • Loading branch information
EagleoutIce authored Mar 11, 2024
2 parents 368b5c6 + 0719f18 commit f478b8b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
27 changes: 17 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export let flowrSession: FlowrInternalSession | FlowrServerSession | undefined
export let outputChannel: vscode.OutputChannel
export let sliceDecoration: vscode.TextEditorDecorationType

let serverStatus: vscode.StatusBarItem
let flowrStatus: vscode.StatusBarItem

export function activate(context: vscode.ExtensionContext) {
console.log('Loading vscode-flowr')
Expand Down Expand Up @@ -59,9 +59,9 @@ export function activate(context: vscode.ExtensionContext) {
void vscode.env.openExternal(vscode.Uri.parse('https://github.com/Code-Inspect/flowr/issues/new/choose'))
}))

serverStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
context.subscriptions.push(serverStatus)
updateServerStatus()
flowrStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
context.subscriptions.push(flowrStatus)
updateStatusBar()

vscode.workspace.onDidChangeConfiguration(e => {
if(e.affectsConfiguration('vscode-flowr.style.sliceOpacity')) {
Expand Down Expand Up @@ -91,26 +91,33 @@ export function isVerbose(): boolean {
export function establishInternalSession() {
destroySession()
flowrSession = new FlowrInternalSession(outputChannel)
updateServerStatus()
updateStatusBar()
}

export function establishServerSession() {
destroySession()
flowrSession = new FlowrServerSession(outputChannel)
updateServerStatus()
updateStatusBar()
}

export function destroySession() {
flowrSession?.destroy()
flowrSession = undefined
}

export function updateServerStatus() {
export function updateStatusBar() {
if(flowrSession instanceof FlowrServerSession) {
serverStatus.show()
serverStatus.text = `$(server) flowR ${flowrSession.state}`
flowrStatus.show()
flowrStatus.text = `$(cloud) flowR server ${flowrSession.state}`
flowrStatus.tooltip = flowrSession.state === 'connected' ?
`R version ${flowrSession.rVersion}\nflowR version ${flowrSession.flowrVersion}` : undefined
} else if(flowrSession instanceof FlowrInternalSession) {
flowrStatus.show()
flowrStatus.text = `$(console) flowR shell ${flowrSession.state}`
flowrStatus.tooltip = flowrSession.state === 'active' ?
`R version ${flowrSession.rVersion}` : undefined
} else {
serverStatus.hide()
flowrStatus.hide()
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/flowr/internal-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import type { NodeId, RShellOptions, SingleSlicingCriterion} from '@eagleoutice/
import { LAST_STEP, requestFromInput, RShell, SteppingSlicer } from '@eagleoutice/flowr'
import type { SourceRange } from '@eagleoutice/flowr/util/range'
import { isNotUndefined } from '@eagleoutice/flowr/util/assert'
import { BEST_R_MAJOR, MINIMUM_R_MAJOR, createSliceDecorations, getConfig, isVerbose, sliceDecoration } from '../extension'
import { BEST_R_MAJOR, MINIMUM_R_MAJOR, createSliceDecorations, getConfig, isVerbose, sliceDecoration, updateStatusBar } from '../extension'

export class FlowrInternalSession {

public state: 'loading' | 'active' | 'failure'
public rVersion: string | undefined

private readonly outputChannel: vscode.OutputChannel
private readonly shell: RShell

constructor(outputChannel: vscode.OutputChannel) {
this.outputChannel = outputChannel
this.outputChannel.appendLine('Using internal flowR')

this.state = 'loading'
updateStatusBar()

let options: Partial<RShellOptions> = {
revive: 'always',
sessionName: 'flowr - vscode'
Expand All @@ -39,13 +46,20 @@ export class FlowrInternalSession {
void vscode.env.openExternal(vscode.Uri.parse('https://github.com/Code-Inspect/vscode-flowr/blob/main/README.md#using'))
}
})

this.state = 'failure'
updateStatusBar()
} else {
this.outputChannel.appendLine(`Using R version ${version.toString()}`)
if(version.major < MINIMUM_R_MAJOR) {
void vscode.window.showErrorMessage(`You are using R version ${version.toString()}, which is not compatible with flowR.`)
void vscode.window.showErrorMessage(`You are using R version ${version.toString()}, but ${MINIMUM_R_MAJOR}.0.0 or higher is required.`)
} else if(version.major < BEST_R_MAJOR) {
void vscode.window.showWarningMessage(`You are using R version ${version.toString()}, which flowR has not been tested for. Some things might not work correctly.`)
void vscode.window.showWarningMessage(`You are using R version ${version.toString()}, which flowR has not been tested for. Version ${BEST_R_MAJOR}.0.0 or higher is recommended.`)
}

this.state = 'active'
this.rVersion = version.toString()
updateStatusBar()
}
})
}
Expand Down
26 changes: 17 additions & 9 deletions src/flowr/server-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import { visitAst } from '@eagleoutice/flowr'
import type { SourceRange } from '@eagleoutice/flowr/util/range'
import { isNotUndefined } from '@eagleoutice/flowr/util/assert'
import { FlowrInternalSession } from './internal-session'
import { createSliceDecorations, establishInternalSession, getConfig, isVerbose, sliceDecoration, updateServerStatus } from '../extension'
import { createSliceDecorations, establishInternalSession, getConfig, isVerbose, sliceDecoration, updateStatusBar } from '../extension'
import type { FlowrHelloResponseMessage } from '@eagleoutice/flowr/cli/repl/server/messages/hello'

export class FlowrServerSession {

public state: 'connecting' | 'connected' | 'not connected'
public state: 'connecting' | 'connected' | 'not connected'
public flowrVersion: string | undefined
public rVersion: string | undefined

private readonly outputChannel: vscode.OutputChannel
private socket: net.Socket
Expand All @@ -22,18 +25,23 @@ export class FlowrServerSession {
this.outputChannel = outputChannel

this.state = 'connecting'
updateServerStatus()
updateStatusBar()

// the first response will be flowR's hello message
void this.awaitResponse().then(r => {
const info = JSON.parse(r) as FlowrHelloResponseMessage
this.rVersion = info.versions.r
this.flowrVersion = info.versions.flowr
updateStatusBar()
})

const host = getConfig().get<string>('server.host', 'localhost')
const port = getConfig().get<number>('server.port', 1042)
this.outputChannel.appendLine(`Connecting to flowR server at ${host}:${port}`)
this.socket = net.createConnection(port, host, () => {
this.state = 'connected'
updateServerStatus()

const msg = 'Connected to flowR server'
this.outputChannel.appendLine(msg)
void vscode.window.showInformationMessage(msg)
updateStatusBar()
this.outputChannel.appendLine('Connected to flowR server')
})
this.socket.on('error', e => {
this.outputChannel.appendLine(`flowR server error: ${e.message}`)
Expand All @@ -49,7 +57,7 @@ export class FlowrServerSession {
this.socket.on('close', () => {
this.outputChannel.appendLine('flowR server connection closed')
this.state = 'not connected'
updateServerStatus()
updateStatusBar()
})
this.socket.on('data', str => this.handleResponse(String(str)))
}
Expand Down

0 comments on commit f478b8b

Please sign in to comment.