Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
feat: support qmlls with e2e tests for configuration changes
Browse files Browse the repository at this point in the history
Fix: #251
  • Loading branch information
seanwu1105 committed Feb 10, 2023
1 parent 7d83a0f commit 87b49e1
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 18.10.0
python 3.10.6
python 3.11.1
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
],
"activationEvents": [
"onLanguage:qml",
"workspaceContains:**/*.qml",
"workspaceContains:**/*.ui",
"onCommand:qtForPython.compileResource",
"onCommand:qtForPython.compileUi",
Expand Down
2 changes: 1 addition & 1 deletion python/.tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python 3.10.6
python 3.11.1
2 changes: 1 addition & 1 deletion python/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"python.defaultInterpreterPath": "./.venv/bin/python", // This is required for e2e tests.
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": ["--rcfile=python/.pylintrc"],
"python.linting.mypyEnabled": true
}
20 changes: 10 additions & 10 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export async function resolveScriptCommand({
resource,
}: ResolveScriptCommandArgs): Promise<ResolveScriptCommandResult> {
const pythonInterpreterPathResult = await getPythonInterpreterPath(resource)
if (pythonInterpreterPathResult.kind === 'Success') {
return {
kind: 'Success',
value: [
...pythonInterpreterPathResult.value,
path.join(extensionUri.fsPath, 'python', 'scripts', `${tool}.py`),
],
}
}

return pythonInterpreterPathResult
if (pythonInterpreterPathResult.kind !== 'Success')
return pythonInterpreterPathResult

return {
kind: 'Success',
value: [
...pythonInterpreterPathResult.value,
path.join(extensionUri.fsPath, 'python', 'scripts', `${tool}.py`),
],
}
}

export type ResolveScriptCommandArgs = {
Expand Down
8 changes: 3 additions & 5 deletions src/qmlls/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ export async function registerQmlLanguageServer({
await activateClient()

async function activateClient() {
if (!workspace.getConfiguration('qtForPython.qmlls').get('enabled')) {
await stopClient()
return
}

await stopClient()

if (!workspace.getConfiguration('qtForPython.qmlls').get('enabled')) return

const startClientResult = await startClient({
extensionUri,
outputChannel,
Expand All @@ -51,6 +48,7 @@ export async function registerQmlLanguageServer({
if (startClientResult.kind !== 'Success') return onResult(startClientResult)

client = startClientResult.value
subscriptions.push(client)
}

async function stopClient() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function main() {
})
} catch (err) {
// eslint-disable-next-line no-console
console.error('Failed to run tests')
console.error(err)
process.exit(1)
}
}
Expand Down
155 changes: 155 additions & 0 deletions src/test/suite/qmlls/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import * as assert from 'node:assert'
import * as path from 'node:path'
import type { CompletionList, Diagnostic, TextDocument } from 'vscode'
import { commands, languages, Position, window, workspace } from 'vscode'
import { URI } from 'vscode-uri'
import {
E2E_TIMEOUT,
setupE2EEnvironment,
TEST_ASSETS_PATH,
waitFor,
} from '../test-utils'

suite('qmlls/e2e', () => {
suiteSetup(async function () {
this.timeout(E2E_TIMEOUT)
await setupE2EEnvironment()
})

suite('when open missing_import.qml', () => {
let diagnostics: readonly Diagnostic[]
let document: TextDocument

suiteSetup(async function () {
this.timeout(E2E_TIMEOUT)

document = await openAndShowTestQmlFile('missing_import.qml')
})

test('should contain diagnostics', async () =>
waitFor(() => {
diagnostics = languages.getDiagnostics(document.uri)
assert.ok(diagnostics.length > 0)
})).timeout(E2E_TIMEOUT)

suite('when trigger completion in first line', () => {
const position = new Position(0, 0)

test('should contain Qt completion items', async () => {
const itemResolveCount = 1

const completionList: CompletionList = await commands.executeCommand(
'vscode.executeCompletionItemProvider',
document.uri,
position,
undefined,
itemResolveCount,
)

assert.ok(completionList.items.map(i => i.label).includes('Qt'))
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)

suite('when disable qmlls', () => {
suiteSetup(async function () {
this.timeout(E2E_TIMEOUT)

await workspace
.getConfiguration('qtForPython.qmlls')
.update('enabled', false)
})

suiteTeardown(async function () {
this.timeout(E2E_TIMEOUT)

await workspace
.getConfiguration('qtForPython.qmlls')
.update('enabled', undefined)
})

test('should not contain diagnostic', async () =>
waitFor(() => {
diagnostics = languages.getDiagnostics(document.uri)
assert.ok(diagnostics.length === 0)
})).timeout(E2E_TIMEOUT)

suite('when trigger completion in first line', () => {
const position = new Position(0, 0)

test('should not contain Qt completion item', async () => {
const completionList: CompletionList = await commands.executeCommand(
'vscode.executeCompletionItemProvider',
document.uri,
position,
)

assert.ok(!completionList.items.map(i => i.label).includes('Qt'))
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)

suite('when enable qmlls again', () => {
suiteSetup(async function () {
this.timeout(E2E_TIMEOUT)

await workspace
.getConfiguration('qtForPython.qmlls')
.update('enabled', true)
})

suiteTeardown(async function () {
this.timeout(E2E_TIMEOUT)

await workspace
.getConfiguration('qtForPython.qmlls')
.update('enabled', undefined)
})

test('should contain diagnostic again', async () =>
waitFor(() => {
diagnostics = languages.getDiagnostics(document.uri)
assert.ok(diagnostics.length > 0)
})).timeout(E2E_TIMEOUT)

suite('when trigger completion in first line', () => {
const position = new Position(0, 0)

test('should contain Qt completion item again', async () => {
const completionList: CompletionList =
await commands.executeCommand(
'vscode.executeCompletionItemProvider',
document.uri,
position,
)

assert.ok(completionList.items.map(i => i.label).includes('Qt'))
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)

suite('when open pass.qml', () => {
let diagnostics: readonly Diagnostic[]
let document: TextDocument

suiteSetup(async function () {
this.timeout(E2E_TIMEOUT)

document = await openAndShowTestQmlFile('pass.qml')
})

test('should not contain diagnostic', async () =>
waitFor(() => {
diagnostics = languages.getDiagnostics(document.uri)
assert.ok(diagnostics.length === 0)
})).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)
}).timeout(E2E_TIMEOUT)

async function openAndShowTestQmlFile(filename: string) {
const document = await workspace.openTextDocument(
URI.file(path.resolve(TEST_ASSETS_PATH, 'qml', filename)),
)
await window.showTextDocument(document)
return document
}

0 comments on commit 87b49e1

Please sign in to comment.