Skip to content
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
"bazelbsp.debug.launchConfigName": {
"type": "string",
"description": "Name of launch configuration that will be executed to begin the DAP debugging session. This must be a valid launch configuration in the launch.json file, workspace, or contributed by another extension."
},
"bazelbsp.java.useDocumentSymbols": {
"type": "boolean",
"default": false,
"description": "Use document symbols to find test cases in Java files. We will fall back to regex if this is not enabled."
}
}
},
Expand Down
15 changes: 13 additions & 2 deletions src/language-tools/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {DocumentTestItem, LanguageTools, TestFileContents} from './manager'
import {TestFinish} from '../bsp/bsp'
import {JUnitStyleTestCaseData, TestFinishDataKind} from '../bsp/bsp-ext'
import {SourceFileTestCaseInfo, TestCaseInfo} from '../test-info/test-info'
import {getExtensionSetting, SettingName} from '../utils/settings'

const TEST_FILE_REGEX = /^(Test.+\.java|.+Test\.java)$/
const JAVA_TEST_REGEX =
Expand Down Expand Up @@ -76,8 +77,18 @@ export class JavaLanguageTools implements LanguageTools {
}
}

// Attempt to get document symbols via VS Code API.
// TODO(IDE-1109): Request document symbols and process them.
// Check if document symbols feature is enabled
const useDocumentSymbols = getExtensionSetting(
SettingName.JAVA_USE_DOCUMENT_SYMBOLS
)
if (useDocumentSymbols) {
// Attempt to get document symbols via VS Code API.
// TODO(IDE-1109): Request document symbols and process them.
return {
isTestFile: false,
testCases: [],
}
}

// Fallback to resolve directly from document text.
// Due to the variety of VS Code extensions and setups in the JVM ecosystem, this allows basic functionality even if the user is missing other extensions or has them misconfigured.
Expand Down
22 changes: 22 additions & 0 deletions src/test/suite/language-tools/java.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
TestItemTestCaseInfo,
} from '../../../test-info/test-info'
import {sampleBuildTarget} from '../test-utils'
import * as sinon from 'sinon'
import * as settings from '../../../utils/settings'

const fixtureDir = path.join(
__dirname,
Expand All @@ -25,13 +27,18 @@ const fixtureDir = path.join(
suite('Java Language Tools', () => {
let languageTools: JavaLanguageTools
let testController: vscode.TestController
let settingsStub: sinon.SinonStub
const sandbox = sinon.createSandbox()

beforeEach(async () => {
testController = vscode.tests.createTestController('java sample', 'sample')
languageTools = new JavaLanguageTools()
settingsStub = sandbox.stub(settings, 'getExtensionSetting')
})

afterEach(async () => {
testController.dispose()
sandbox.restore()
})

test('process test cases, example 1', async () => {
Expand Down Expand Up @@ -402,4 +409,19 @@ suite('Java Language Tools', () => {
result = languageTools.mapTestCaseInfoToLookupKey(testCaseInfo)
assert.strictEqual(result, undefined)
})

test('document symbols feature enabled but not implemented', async () => {
settingsStub
.withArgs(settings.SettingName.JAVA_USE_DOCUMENT_SYMBOLS)
.returns(true)

const result = await languageTools.getDocumentTestCases(
vscode.Uri.file(
path.join(fixtureDir, 'language_files', 'SampleValidExampleTest.java')
)
)
assert.strictEqual(result.isTestFile, false)
assert.strictEqual(result.testCases.length, 0)
assert.strictEqual(result.documentTest, undefined)
})
})
2 changes: 2 additions & 0 deletions src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum SettingName {
DEBUG_BAZEL_FLAGS = 'debug.bazelFlags',
LAUNCH_CONFIG_NAME = 'debug.launchConfigName',
DEBUG_READY_PATTERN = 'debug.readyPattern',
JAVA_USE_DOCUMENT_SYMBOLS = 'java.useDocumentSymbols',
ADDITIONAL_INSTALL_FLAGS = 'additionalInstallFlags',
}

Expand All @@ -27,6 +28,7 @@ export interface SettingTypes {
[SettingName.DEBUG_BAZEL_FLAGS]: string[]
[SettingName.LAUNCH_CONFIG_NAME]: string
[SettingName.DEBUG_READY_PATTERN]: string
[SettingName.JAVA_USE_DOCUMENT_SYMBOLS]: boolean
[SettingName.ADDITIONAL_INSTALL_FLAGS]: string[]
}

Expand Down