Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL + Tests using Wollok-CLI #37

Merged
merged 5 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/package-lock.json

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

41 changes: 41 additions & 0 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as path from 'path'
import { commands, ExtensionContext, ShellExecution, Task, tasks, window, workspace } from 'vscode'


export const subscribeWollokCommands = (context: ExtensionContext): void => {
context.subscriptions.push(registerCLICommand('wollok.start.repl', startRepl))
context.subscriptions.push(registerCLICommand('wollok.run.allTests', runAllTests))
}

/**
* CLI Commands
*/

const runAllTests = () => wollokCLITask('run tests', 'Wollok run all tests', ['test'])

const startRepl = () => {
const currentDocument = window.activeTextEditor.document
const currentFileName = path.basename(currentDocument.uri.path)
return wollokCLITask('repl', `Wollok Repl: ${currentFileName}`, ['repl', currentDocument.fileName])
}

/**
* Helpers
*/

const registerCLICommand = (command: string, taskBuilder: () => Task) =>
commands.registerCommand(command, () => tasks.executeTask(taskBuilder()))

const wollokCLITask = (task: string, name: string, cliCommands: string[]) => {
const wollokCli = workspace.getConfiguration('wollokLinter').get('cli-path')
const folder = workspace.workspaceFolders[0]
const shellCommand = [wollokCli, ...cliCommands].join(' ')

return new Task(
{ type: 'wollok', task },
folder,
name,
'wollok',
new ShellExecution(shellCommand)
)
}
Empty file removed client/src/completion.ts
Empty file.
7 changes: 6 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* ------------------------------------------------------------------------------------------ */

import * as path from 'path'
import { workspace, ExtensionContext } from 'vscode'
import { ExtensionContext, workspace } from 'vscode'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sí Linter, ordenado como debe estar cada import 😄

import { LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind } from 'vscode-languageclient/node'
import { subscribeWollokCommands } from './commands'

let client: LanguageClient

Expand Down Expand Up @@ -43,6 +44,10 @@ export function activate(context: ExtensionContext): void {
},
}

// Subscribe Wollok Commands
subscribeWollokCommands(context)


// Create the language client and start the client.
client = new LanguageClient(
'wollok-lsp-ide',
Expand Down
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
"type": "object",
"title": "Wollok LSP IDE",
"properties": {
"wollokLinter.cli-path": {
"scope": "resource",
"type": "string",
"description": "Path to Wollok-CLI."
},
"wollokLinter.maxNumberOfProblems": {
"scope": "resource",
"type": "number",
Expand Down Expand Up @@ -75,7 +80,20 @@
"description": "Traces the communication between VS Code and the language server."
}
}
}
},
"commands": [
{
"command": "wollok.start.repl",
"title": "Start a new REPL session",
"category": "Wollok"
},
{
"command": "wollok.run.allTests",
"title": "Run all tests",
"when": "resourceExtname == .wtest",
"category": "Wollok"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
Expand Down