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

Strip Java case insensitive flags #108

Merged
merged 3 commits into from
Oct 10, 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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added
- Add support for [document symbols](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentSymbol) ([#98](https://github.com/cucumber/language-service/issues/98), [#106](https://github.com/cucumber/language-service/pull/106))
- (Java) Recognise regexps with `(?i)`, with the caveat that the resulting JavaScript `RegExp` is *not* case insensitive ([#100](https://github.com/cucumber/language-service/issues/100), [#108](https://github.com/cucumber/language-service/pull/108))
- (TypeScript) Add support for template literals without subsitutions. ([#101](https://github.com/cucumber/language-service/issues/101), [#107](https://github.com/cucumber/language-service/pull/107))

## [1.0.1] - 2022-10-10
Expand Down Expand Up @@ -326,5 +327,3 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[0.2.0]: https://github.com/cucumber/language-service/compare/v0.1.1...v0.2.0
[0.1.1]: https://github.com/cucumber/language-service/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/cucumber/language-service/tree/v0.1.0
0...v0.1.1
[0.1.0]: https://github.com/cucumber/language-service/tree/v0.1.0
5 changes: 3 additions & 2 deletions src/language/javaLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ export const javaLanguage: Language = {
`,
}

function stringLiteral(node: TreeSitterSyntaxNode | null): string {
export function stringLiteral(node: TreeSitterSyntaxNode | null): string {
if (node === null) throw new Error('node cannot be null')
return unescapeString(node.text.slice(1, -1))
const string = node.text.slice(1, -1)
return unescapeString(string.replace('(?i)', ''))
}

// Java escapes \ as \\. Turn \\ back to \.
Expand Down
18 changes: 18 additions & 0 deletions test/language/javaLanguage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'assert'

import { stringLiteral } from '../../src/language/javaLanguage.js'
import { TreeSitterSyntaxNode } from '../../src/language/types.js'

describe('javaLanguage', () => {
it('should remove (?i) from regexp strings', () => {
const node: TreeSitterSyntaxNode = {
type: 'string_literal',
text: '"(?i)(day|hour)s?"',
startPosition: { row: 1, column: 19 },
endPosition: { row: 1, column: 37 },
children: [],
}
const result = stringLiteral(node)
assert.deepStrictEqual(result, '(day|hour)s?')
})
})
4 changes: 2 additions & 2 deletions test/language/rubyLanguage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TreeSitterSyntaxNode } from '../../src/language/types.js'

describe('rubyLanguage', () => {
it('should preserve regexp flags in step definitions', () => {
const regex: TreeSitterSyntaxNode = {
const node: TreeSitterSyntaxNode = {
type: 'regex',
text: '/^a regexp$/i',
startPosition: { row: 0, column: 6 },
Expand All @@ -20,7 +20,7 @@ describe('rubyLanguage', () => {
},
],
}
const result = toStringOrRegExp(regex)
const result = toStringOrRegExp(node)
assert.deepStrictEqual(result, /^a regexp$/i)
})
})