Skip to content

Commit

Permalink
feat(model): resolve languageID for spring-boot
Browse files Browse the repository at this point in the history
Related #5028

A better way is adding a languageID pattern in languageserver/extension configuration, but this needs pass through more layers, needs more works, just made this quickfix for now.
  • Loading branch information
fannheyward committed Dec 18, 2024
1 parent a6e54ae commit 2dd045b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/__tests__/modules/document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ describe('Document', () => {
await nvim.command(`edit +setl\\ filetype=txt.vim foo`)
let doc = await workspace.document
expect(doc.languageId).toBe('txt')

await nvim.command(`edit +setl\\ filetype=jproperties application.properties`)
doc = await workspace.document
expect(doc.languageId).toBe('spring-boot-properties')

await nvim.command(`edit +setl\\ filetype=jproperties bootstrap.test.properties`)
doc = await workspace.document
expect(doc.languageId).toBe('spring-boot-properties')

await nvim.command(`edit +setl\\ filetype=yaml application.yml`)
doc = await workspace.document
expect(doc.languageId).toBe('spring-boot-properties-yaml')

await nvim.command(`edit +setl\\ filetype=yaml application.test.yaml`)
doc = await workspace.document
expect(doc.languageId).toBe('spring-boot-properties-yaml')
})

it('should parse iskeyword of character range', async () => {
Expand Down
11 changes: 10 additions & 1 deletion src/model/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,16 @@ export default class Document {
*/
public get languageId(): string {
let { _filetype } = this
return _filetype.includes('.') ? _filetype.match(/(.*?)\./)[1] : _filetype
const ft = _filetype.includes('.') ? _filetype.match(/(.*?)\./)[1] : _filetype

if (ft === 'jproperties' && /(application|bootstrap).*\.properties$/.test(this._bufname)) {
return 'spring-boot-properties'
}
if (ft === 'yaml' && /(application|bootstrap).*\.ya?ml$/.test(this._bufname)) {
return 'spring-boot-properties-yaml'
}

return ft
}

/**
Expand Down

0 comments on commit 2dd045b

Please sign in to comment.