Skip to content

Commit

Permalink
fixes a bug where a space or slash typed in quoted cause the text to be
Browse files Browse the repository at this point in the history
removed
fixes a bug where a typed '/' inserted '/>'
fixes a bug where a space typed on a blank line trigger intellisense for
the item in the line above
modified hover behavoior to produce definitions for dfdl attributes
only

closes apache#1064
  • Loading branch information
rthomas320 committed Jul 19, 2024
1 parent 1329b4f commit 9376305
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/language/providers/attributeHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import * as vscode from 'vscode'
import { attributeHoverValues } from './intellisense/attributeHoverItems'
import { attributeCompletion } from './intellisense/attributeItems'

export function getAttributeHoverProvider() {
return vscode.languages.registerHoverProvider('dfdl', {
Expand All @@ -28,11 +29,17 @@ export function getAttributeHoverProvider() {
const range = document.getWordRangeAtPosition(position)
const word = document.getText(range)

let itemNames: string[] = []
attributeCompletion('', '', 'dfdl:', '', '').items.forEach((r) =>
itemNames.push(r.item)
)
if (word.length > 0) {
return new vscode.Hover({
language: 'dfdl',
value: attributeHoverValues(word),
})
if (itemNames.includes(word)) {
return new vscode.Hover({
language: 'dfdl',
value: attributeHoverValues(word),
})
}
}
},
})
Expand Down
18 changes: 14 additions & 4 deletions src/language/providers/attributeValueCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ export function getAttributeValueCompletionProvider() {
replaceValue = ' '
}

if (attributeName.includes(':')) {
if (
attributeName.includes(':') &&
!attributeName.includes('xmlns:')
) {
attributeName = attributeName.substring(
attributeName.indexOf(':') + 1
)
}

if (noChoiceAttributes.includes(attributeName)) {
if (
noChoiceAttributes.includes(attributeName) ||
attributeName.includes('xmlns:')
) {
return undefined
}

Expand All @@ -75,7 +81,7 @@ export function getAttributeValueCompletionProvider() {
return undefined
},
},
' ' // triggered whenever a newline is typed
' ' // triggered whenever a space is typed
)
}

Expand Down Expand Up @@ -130,7 +136,7 @@ export function getTDMLAttributeValueCompletionProvider() {
return undefined
},
},
' ' // triggered whenever a newline is typed
' ' // triggered whenever a space is typed
)
}

Expand Down Expand Up @@ -182,6 +188,10 @@ function getAttributeDetails(
currentPos < triggerPos &&
textBeforeTrigger.lastIndexOf('=') === currentPos - 1
) {
textBeforeTrigger = textBeforeTrigger.substring(
0,
textBeforeTrigger.lastIndexOf('=')
)
endPos = currentText.indexOf(quoteChar[i], currentPos + 1)
attributeStartPos = textBeforeTrigger.lastIndexOf(' ')
attributeName = textBeforeTrigger.substring(
Expand Down
3 changes: 3 additions & 0 deletions src/language/providers/closeElementSlash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export function getCloseElementSlashProvider() {
position,
nsPrefix
)
if (nearestTagNotClosed === 'none') {
return undefined
}
const itemsOnLine = getItemsOnLineCount(triggerText)

if (
Expand Down
3 changes: 3 additions & 0 deletions src/language/providers/intellisense/attributeValueItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const noChoiceAttributes = [
'test',
'testPattern',
'message',
'source',
'schemaLocation',
'targetNamespace',
]

export function attributeValues(
Expand Down
11 changes: 10 additions & 1 deletion src/language/providers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,19 @@ export function checkTagOpen(
const triggerPos = position.character
const textBeforeTrigger = triggerText.substring(0, triggerPos)

while (itemsOnLine < 2 && !triggerText.trim().startsWith('<')) {
while (
itemsOnLine < 2 &&
!triggerText.trim().startsWith('<') &&
!triggerText.includes('/>') &&
!triggerText.includes('<')
) {
triggerText = document.lineAt(--triggerLine).text
}

if (triggerText.includes('/>') || triggerText.includes('</')) {
return false
}

if (!(triggerText.endsWith('>') && triggerText.includes('<'))) {
isMultiLineTag = true
}
Expand Down

0 comments on commit 9376305

Please sign in to comment.