Skip to content

Commit a0328e1

Browse files
committed
fix: don't show dub.sdl errors with missing values
Instead show just an information (blue underline), also don't show it inside configurations or build types, since they might override existing values to be null in that case.
1 parent de9eaea commit a0328e1

File tree

1 file changed

+54
-17
lines changed

1 file changed

+54
-17
lines changed

src/sdl/sdl-contributions.ts

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ interface CompletionTag {
276276
values?: CompletionValues;
277277
attributes?: CompletionAttributeMap;
278278
minValues?: number;
279+
suggestShouldHaveValues?: boolean;
279280
maxValues?: number;
280281
tags?: CompletionTagMap | null;
281282
requireTags?: boolean;
@@ -499,25 +500,29 @@ const buildSettings: CompletionTagMap = {
499500
type: "string"
500501
},
501502
attributes: platformAttributes,
502-
minValues: 1
503+
minValues: 0,
504+
suggestShouldHaveValues: true
503505
},
504506
sourceFiles: {
505507
description: "Additional files passed to the compiler - can be useful to add certain configuration dependent source files that are not contained in the general source folder",
506508
values: pathComplete,
507509
attributes: platformAttributes,
508-
minValues: 1
510+
minValues: 0,
511+
suggestShouldHaveValues: true
509512
},
510513
sourcePaths: {
511514
description: `Allows to customize the path where to look for source files (any folder "source" or "src" is automatically used as a source path if no sourcePaths setting is specified) - note that you usually also need to define "importPaths" as "sourcePaths" don't influence those`,
512515
values: pathComplete,
513516
attributes: platformAttributes,
514-
minValues: 1
517+
minValues: 0
518+
// default: source, so empty is valid and not a warning
515519
},
516520
excludedSourceFiles: {
517521
description: 'Files that should be removed for the set of already added source files (takes precedence over "sourceFiles" and "sourcePaths") - Glob matching can be used to pattern match multiple files at once',
518522
values: pathComplete,
519523
attributes: platformAttributes,
520-
minValues: 1
524+
minValues: 0,
525+
suggestShouldHaveValues: true
521526
},
522527
mainSourceFile: {
523528
description: 'Determines the file that contains the main() function. This setting can be used by dub to exclude this file in situations where a different main function is defined (e.g. for "dub test") - this setting does not support platform suffixes',
@@ -529,83 +534,94 @@ const buildSettings: CompletionTagMap = {
529534
description: 'A list of globs matching files or directories to be copied to targetPath. Matching directories are copied recursively, i.e. "copyFiles": ["path/to/dir"]" recursively copies dir, while "copyFiles": ["path/to/dir/*"]" only copies files within dir.',
530535
values: pathComplete,
531536
attributes: platformAttributes,
532-
minValues: 1
537+
minValues: 0,
538+
suggestShouldHaveValues: true
533539
},
534540
versions: {
535541
description: "A list of D versions to be defined during compilation",
536542
values: {
537543
type: "string"
538544
},
539545
attributes: platformAttributes,
540-
minValues: 1
546+
minValues: 0,
547+
suggestShouldHaveValues: true
541548
},
542549
debugVersions: {
543550
description: "A list of D debug identifiers to be defined during compilation",
544551
values: {
545552
type: "string"
546553
},
547554
attributes: platformAttributes,
548-
minValues: 1
555+
minValues: 0,
556+
suggestShouldHaveValues: true
549557
},
550558
importPaths: {
551559
description: "Additional import paths to search for D modules (the source/ folder is used by default as a source folder, if it exists)",
552560
values: pathComplete,
553561
attributes: platformAttributes,
554-
minValues: 1
562+
minValues: 0
563+
// default: source, so empty is valid and not a warning
555564
},
556565
stringImportPaths: {
557566
description: "Additional import paths to search for string imports/views (the views/ folder is used by default as a string import folder, if it exists)",
558567
values: pathComplete,
559568
attributes: platformAttributes,
560-
minValues: 1
569+
minValues: 0
570+
// default: views, so empty is valid and not a warning
561571
},
562572
preGenerateCommands: {
563573
description: "A list of shell commands that is executed before project generation is started",
564574
values: {
565575
type: "string"
566576
},
567577
attributes: platformAttributes,
568-
minValues: 1
578+
minValues: 0,
579+
suggestShouldHaveValues: true
569580
},
570581
postGenerateCommands: {
571582
description: "A list of shell commands that is executed after project generation is finished",
572583
values: {
573584
type: "string"
574585
},
575586
attributes: platformAttributes,
576-
minValues: 1
587+
minValues: 0,
588+
suggestShouldHaveValues: true
577589
},
578590
preBuildCommands: {
579591
description: "A list of shell commands that is executed always before the project is built",
580592
values: {
581593
type: "string"
582594
},
583595
attributes: platformAttributes,
584-
minValues: 1
596+
minValues: 0,
597+
suggestShouldHaveValues: true
585598
},
586599
postBuildCommands: {
587600
description: "A list of shell commands that is executed always after the project is built",
588601
values: {
589602
type: "string"
590603
},
591604
attributes: platformAttributes,
592-
minValues: 1
605+
minValues: 0,
606+
suggestShouldHaveValues: true
593607
},
594608
preRunCommands: {
595609
description: "A list of shell commands that is executed always before the project is built",
596610
values: {
597611
type: "string"
598612
},
599613
attributes: platformAttributes,
600-
minValues: 1
614+
minValues: 0,
615+
suggestShouldHaveValues: true
601616
},
602617
postRunCommands: {
603618
description: "A list of shell commands that is executed always after the project is built",
604619
values: {
605620
type: "string"
606621
},
607622
attributes: platformAttributes,
608-
minValues: 1
623+
minValues: 0,
624+
suggestShouldHaveValues: true
609625
},
610626
environments: {
611627
description: "Environment variables to pass to every invoked build tool, program or script. (lowest precedence)\n\n```\nenvironments \"key\" \"value\"\n```",
@@ -713,6 +729,24 @@ function merge(a: OptionalCompletionTagMap, b: OptionalCompletionTagMap): Comple
713729
return obj;
714730
}
715731

732+
function map(obj: CompletionTagMap, fn: (t: CompletionTag) => CompletionTag): CompletionTagMap {
733+
var d: CompletionTagMap = {};
734+
for (const k in obj)
735+
if (obj.hasOwnProperty(k))
736+
d[k] = fn(obj[k]);
737+
return d;
738+
}
739+
740+
function removeField(fieldName: keyof CompletionTag): (t: CompletionTag) => CompletionTag {
741+
return function(obj: CompletionTag) {
742+
if (fieldName in obj) {
743+
obj = JSON.parse(JSON.stringify(obj));
744+
delete obj[fieldName];
745+
}
746+
return obj;
747+
}
748+
}
749+
716750
let dubSchema = {
717751
title: "dub Package Schema",
718752
description: "dub package file",
@@ -828,7 +862,7 @@ let dubSchema = {
828862
values: {
829863
type: "string"
830864
},
831-
tags: merge(buildSettings, {
865+
tags: merge(map(buildSettings, removeField("suggestShouldHaveValues")), {
832866
platforms: {
833867
description: "A list of platform specifiers to limit on which platforms the configuration applies",
834868
values: {
@@ -845,7 +879,7 @@ let dubSchema = {
845879
values: {
846880
type: "string"
847881
},
848-
tags: merge(buildSettings, {
882+
tags: merge(map(buildSettings, removeField("suggestShouldHaveValues")), {
849883
dependency: undefined,
850884
targetType: undefined,
851885
targetName: undefined,
@@ -1063,6 +1097,9 @@ export class SDLContributions implements vscode.CompletionItemProvider {
10631097
if (typeof obj.minValues == "number")
10641098
if (tag.values.length < obj.minValues && tag.range)
10651099
errors.push(new vscode.Diagnostic(range(tag.range), "Not enough values. Requires at least " + obj.minValues, vscode.DiagnosticSeverity.Error));
1100+
if (obj.suggestShouldHaveValues)
1101+
if (tag.values.length == 0 && tag.range)
1102+
errors.push(new vscode.Diagnostic(range(tag.range), "This directive should specify some values, otherwise it might not have any effect", vscode.DiagnosticSeverity.Information));
10661103
if (typeof obj.maxValues == "number")
10671104
if (tag.values.length > obj.maxValues && tag.range)
10681105
errors.push(new vscode.Diagnostic(range(tag.range), "Too many values. Allows at most " + obj.maxValues, vscode.DiagnosticSeverity.Error));

0 commit comments

Comments
 (0)