Skip to content

Commit 9fde069

Browse files
committed
Started on 1221
1 parent 33a1f57 commit 9fde069

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

src/consts/dfdlElements.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const DFDL_ASSERT_ELEMENT_NAME = 'dfdl:assert'
2+
export const DFDL_DEFINE_VARIABLE_ELEMENT_NAME = 'dfdl:defineVariable'
3+
export const DFDL_DISCRIMINATOR_ELEMENT_NAME = 'dfdl:discriminator'
4+
5+
export default {
6+
DFDL_DISCRIMINATOR_ELEMENT_NAME: DFDL_DISCRIMINATOR_ELEMENT_NAME,
7+
DFDL_DEFINE_VARIABLE: DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
8+
DFDL_ASSERT_ELEMENT_NAME: DFDL_ASSERT_ELEMENT_NAME,
9+
}

src/language/providers/elementCompletion.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import {
3333
cursorAfterEquals,
3434
} from './utils'
3535
import { elementCompletion } from './intellisense/elementItems'
36+
import {
37+
DFDL_ASSERT_ELEMENT_NAME,
38+
DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
39+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
40+
} from 'consts/dfdlElements'
3641

3742
export function getElementCompletionProvider(dfdlFormatString: string) {
3843
return vscode.languages.registerCompletionItemProvider(
@@ -318,7 +323,7 @@ function nearestOpenTagChildElements(
318323
return getElementCompletionItems(
319324
[
320325
'dfdl:defineFormat',
321-
'dfdl:defineVariable',
326+
DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
322327
'dfdl:defineEscapeScheme',
323328
'dfdl:format',
324329
],
@@ -329,8 +334,8 @@ function nearestOpenTagChildElements(
329334
case 'element':
330335
return getElementCompletionItems(
331336
[
332-
'dfdl:assert',
333-
'dfdl:discriminator',
337+
DFDL_ASSERT_ELEMENT_NAME,
338+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
334339
'dfdl:element',
335340
'dfdl:setVariable',
336341
'dfdl:property',
@@ -342,8 +347,8 @@ function nearestOpenTagChildElements(
342347
case 'sequence':
343348
return getElementCompletionItems(
344349
[
345-
'dfdl:assert',
346-
'dfdl:discriminator',
350+
DFDL_ASSERT_ELEMENT_NAME,
351+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
347352
'dfdl:newVariableInstance',
348353
'dfdl:sequence',
349354
],
@@ -354,9 +359,9 @@ function nearestOpenTagChildElements(
354359
case 'choice':
355360
return getElementCompletionItems(
356361
[
357-
'dfdl:assert',
362+
DFDL_ASSERT_ELEMENT_NAME,
358363
'dfdl:choice',
359-
'dfdl:discriminator',
364+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
360365
'dfdl:newVariableInstance',
361366
'dfdl:setVariable',
362367
],
@@ -367,9 +372,9 @@ function nearestOpenTagChildElements(
367372
case 'group':
368373
return getElementCompletionItems(
369374
[
370-
'dfdl:assert',
375+
DFDL_ASSERT_ELEMENT_NAME,
371376
'dfdl:group',
372-
'dfdl:discriminator',
377+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
373378
'dfdl:newVariableInstance',
374379
'dfdl:setVariable',
375380
],
@@ -380,8 +385,8 @@ function nearestOpenTagChildElements(
380385
case 'simpleType':
381386
return getElementCompletionItems(
382387
[
383-
'dfdl:assert',
384-
'dfdl:discriminator',
388+
DFDL_ASSERT_ELEMENT_NAME,
389+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
385390
'dfdl:setVariable',
386391
'dfdl:simpleType',
387392
'dfdl:property',

src/language/providers/intellisense/attributeHoverItems.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { DFDL_ASSERT_ELEMENT_NAME } from 'consts/dfdlElements'
19+
1820
export function attributeHoverValues(attributeName: string): string {
1921
switch (attributeName) {
2022
case 'name':
@@ -216,15 +218,15 @@ export function attributeHoverValues(attributeName: string): string {
216218
case 'dfdl:escapeCharacterPolicy':
217219
return 'The type of escape mechanism defined in the escape scheme'
218220
case 'testKind':
219-
return 'Specifies whether a DFDL expression or DFDL regular expression pattern is used in the dfdl:assert'
221+
return `Specifies whether a DFDL expression or DFDL regular expression pattern is used in ${DFDL_ASSERT_ELEMENT_NAME}`
220222
case 'test':
221223
return 'A DFDL expression that evaluates to true or false.'
222224
case 'testPattern':
223225
return 'A DFDL regular expression that is applied against the data stream'
224226
case 'message':
225227
return 'Defines text for use in an error message'
226228
case 'failureType':
227-
return 'Specifies the type of failure that occurs when the dfdl:assert is unsuccessful'
229+
return `Specifies the type of failure that occurs when the ${DFDL_ASSERT_ELEMENT_NAME} is unsuccessful`
228230
case 'schemaLocation':
229231
return 'Specifies the location of the schema'
230232
case 'namespace':

src/language/providers/intellisense/attributeItems.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { DFDL_ASSERT_ELEMENT_NAME } from 'consts/dfdlElements'
19+
1820
// prettier-ignore
1921
export const attributeCompletion = (
2022
additionalItems,
@@ -523,7 +525,7 @@ export const attributeCompletion = (
523525
{
524526
item: 'testKind',
525527
snippetString: spacingChar + 'testKind="${1|expression,pattern|}"$0' + afterChar,
526-
markdownString: 'Specifies whether a DFDL expression or DFDL regular expression pattern is used in the dfdl:assert',
528+
markdownString: `Specifies whether a DFDL expression or DFDL regular expression pattern is used in ${DFDL_ASSERT_ELEMENT_NAME}`,
527529
},
528530
{
529531
item: 'test',
@@ -543,7 +545,7 @@ export const attributeCompletion = (
543545
{
544546
item: 'failureType',
545547
snippetString: spacingChar + 'failureType="${1|processingError,recoverableError|}"$0' + afterChar,
546-
markdownString: 'Specifies the type of failure that occurs when the dfdl:assert is unsuccessful',
548+
markdownString: `Specifies the type of failure that occurs when the ${DFDL_ASSERT_ELEMENT_NAME} is unsuccessful`,
547549
},
548550
{
549551
item: 'schemaLocation',

src/language/providers/intellisense/elementItems.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18+
import {
19+
DFDL_ASSERT_ELEMENT_NAME,
20+
DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
21+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
22+
} from 'consts/dfdlElements'
23+
1824
// prettier-ignore
1925
export const elementCompletion = (definedVariables, nsPrefix) => {
2026
return {
@@ -48,13 +54,13 @@ export const elementCompletion = (definedVariables, nsPrefix) => {
4854
markdownString: 'Defines a reference to a group declaration',
4955
},
5056
{
51-
item: 'dfdl:assert',
52-
snippetString: '<' + nsPrefix + 'assert $0',
57+
item: DFDL_ASSERT_ELEMENT_NAME,
58+
snippetString: `<${DFDL_ASSERT_ELEMENT_NAME} $0`,
5359
markdownString: 'Used to assert truths about a DFDL model',
5460
},
5561
{
56-
item: 'dfdl:discriminator',
57-
snippetString: '<' + nsPrefix + 'discriminator $0',
62+
item: DFDL_DISCRIMINATOR_ELEMENT_NAME,
63+
snippetString: `<${DFDL_DISCRIMINATOR_ELEMENT_NAME} $0`,
5864
markdownString: 'Used during parsing to resolve points or uncertainity, remove ambiguity during speculative parsing, improve diagnostic behavior',
5965
},
6066
{
@@ -106,8 +112,8 @@ export const elementCompletion = (definedVariables, nsPrefix) => {
106112
markdownString: 'Defines the name, type, and optional default value for the variable'
107113
},
108114
{
109-
item: 'dfdl:defineVariable',
110-
snippetString: '<' + nsPrefix + 'defineVariable name="$1"$0',
115+
item: DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
116+
snippetString: `<${DFDL_DEFINE_VARIABLE_ELEMENT_NAME} name="$1"$0`,
111117
markdownString: 'Defines the name, type, and optionally default value for the variable.',
112118
},
113119
{

src/tests/suite/language/items.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import * as assert from 'assert'
1919
import { attributeCompletion } from '../../../language/providers/intellisense/attributeItems'
2020
import { commonCompletion } from '../../../language/providers/intellisense/commonItems'
2121
import { elementCompletion } from '../../../language/providers/intellisense/elementItems'
22+
import {
23+
DFDL_ASSERT_ELEMENT_NAME,
24+
DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
25+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
26+
} from 'consts/dfdlElements'
2227

2328
suite('Items Test Suite', () => {
2429
const expectedElementItems = [
@@ -28,8 +33,8 @@ suite('Items Test Suite', () => {
2833
'element ref',
2934
'group name',
3035
'group ref',
31-
'dfdl:assert',
32-
'dfdl:discriminator',
36+
DFDL_ASSERT_ELEMENT_NAME,
37+
DFDL_DISCRIMINATOR_ELEMENT_NAME,
3338
'dfdl:format',
3439
'annotation',
3540
'appinfo',
@@ -40,7 +45,7 @@ suite('Items Test Suite', () => {
4045
'sequence',
4146
'choice',
4247
'dfdl:newVariableInstance',
43-
'dfdl:defineVariable',
48+
DFDL_DEFINE_VARIABLE_ELEMENT_NAME,
4449
'dfdl:setVariable',
4550
'dfdl:defineFormat',
4651
'dfdl:defineEscapeScheme',

0 commit comments

Comments
 (0)