drccrd commented on code in PR #4083:
URL: 
https://github.com/apache/incubator-kie-tools/pull/4083#discussion_r4613798867


##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintHelper.java:
##########
@@ -148,7 +156,7 @@ public static List<Diagnostic> lint(String text) {
         if (mvelSeverity != null) {
             out.addAll(lintMvelPropertyAccess(sanitized, mvelSeverity));
         }
-        return out;
+        return DRLLintSuppression.filter(out, text);

Review Comment:
   the passes already stop at `MAX_DIAGNOSTICS_PER_PASS` before this runs, so 
suppressed diagnostics use up the cap and can hide real ones. e.g. a `disable 
missing-semicolon` region over a rule with 25 missing `;` hides the one real 
missing `;` after the `enable`. same for `lintUnknownTypes` with its cap of 50



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintHelper.java:
##########
@@ -214,6 +222,7 @@ private static List<Diagnostic> lintUnbalancedParens(String 
sanitized,
                         Diagnostic d = new Diagnostic();
                         d.setSeverity(severity);
                         d.setSource("drools-lint");

Review Comment:
   could the sources be constants too, like the new codes? 
`isSuppressibleSource` only works as long as these strings match, and 
`DeprecatedConstructs` and `CompileDiagnostics` already have a `SOURCE` constant



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);

Review Comment:
   `drools-deprecated` should be in here too, suppressing those in legacy files 
is probably the main use case. they'd need a code per family first, and they 
come out of `DRLDiagnosticHelper.parse` so this filter never sees them at the 
moment



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =

Review Comment:
   these four patterns are copies of the ones in `DRLLintHelper`, and 
`findRuleBoundaries` redoes the scan from `lintMissingRuleEnds`. could they 
share one scanner? also, being case-insensitive, a consequence line like `Rule 
r = drools.getRule();` starts a new rule



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);
+    }
+
+    /**
+     * Replaces string literal contents with spaces so directives inside quotes
+     * (e.g. {@code String s = "// @drl-lsp-lint:disable"}) are not treated as 
directives.
+     * Newlines are preserved to keep original line numbers intact.
+     */
+    static String blankStrings(String text) {
+        if (text == null || text.isEmpty()) {
+            return "";
+        }
+        char[] chars = text.toCharArray();
+        boolean inDouble = false;
+        boolean inSingle = false;
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+            if (c == '\n' || c == '\r') {
+                inDouble = false;
+                inSingle = false;
+                continue;
+            }
+            if (inDouble) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '"') {
+                    inDouble = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (inSingle) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '\'') {
+                    inSingle = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (c == '"') {
+                inDouble = true;
+            } else if (c == '\'') {
+                inSingle = true;
+            }
+        }
+        return new String(chars);
+    }
+
+    /**
+     * Index of parsed suppression directives for fast diagnostic filtering.
+     */
+    public static final class SuppressionIndex {
+        private final Set<String> fileSuppressed = new HashSet<>();
+        private final Map<Integer, Set<String>> lineSuppressed = new 
HashMap<>();
+        private boolean hasAnySuppression = false;
+
+        public boolean hasAnySuppression() {
+            return hasAnySuppression;
+        }
+
+        public boolean isSuppressed(Diagnostic d) {
+            if (d == null || !hasAnySuppression) {
+                return false;
+            }
+            if (!isSuppressibleSource(d.getSource())) {
+                return false;
+            }
+            String code = null;
+            if (d.getCode() != null) {
+                if (d.getCode().isLeft()) {
+                    code = d.getCode().getLeft();
+                } else if (d.getCode().isRight()) {
+                    code = String.valueOf(d.getCode().getRight());
+                }
+            }
+
+            if (matches(fileSuppressed, code)) {
+                return true;
+            }
+
+            if (d.getRange() != null && d.getRange().getStart() != null) {
+                int startLine = d.getRange().getStart().getLine();
+                if (matches(lineSuppressed.get(startLine), code)) {
+                    return true;
+                }
+                if (d.getRange().getEnd() != null) {
+                    int endLine = d.getRange().getEnd().getLine();
+                    if (endLine != startLine && 
matches(lineSuppressed.get(endLine), code)) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        private static boolean matches(Set<String> set, String code) {
+            if (set == null || set.isEmpty()) {
+                return false;
+            }
+            if (set.contains("*")) {
+                return true;
+            }
+            return code != null && set.contains(code.toLowerCase(Locale.ROOT));
+        }
+
+        public static SuppressionIndex parse(String text) {
+            SuppressionIndex index = new SuppressionIndex();
+            if (text == null || text.isEmpty()) {
+                return index;
+            }
+
+            // Quick check to bypass regex and line parsing if no directive 
namespace is present
+            if (!text.toLowerCase(Locale.ROOT).contains("@drl-lsp-lint:")) {

Review Comment:
   nit: this copies the whole document on every call even without directives, 
`DIRECTIVE_PATTERN.matcher(text).find()` would avoid that (or it goes away if 
the directives come from the comment tokens)



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);
+    }
+
+    /**
+     * Replaces string literal contents with spaces so directives inside quotes
+     * (e.g. {@code String s = "// @drl-lsp-lint:disable"}) are not treated as 
directives.
+     * Newlines are preserved to keep original line numbers intact.
+     */
+    static String blankStrings(String text) {
+        if (text == null || text.isEmpty()) {
+            return "";
+        }
+        char[] chars = text.toCharArray();
+        boolean inDouble = false;
+        boolean inSingle = false;
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+            if (c == '\n' || c == '\r') {
+                inDouble = false;
+                inSingle = false;
+                continue;
+            }
+            if (inDouble) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '"') {
+                    inDouble = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (inSingle) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '\'') {
+                    inSingle = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (c == '"') {
+                inDouble = true;
+            } else if (c == '\'') {
+                inSingle = true;
+            }
+        }
+        return new String(chars);
+    }
+
+    /**
+     * Index of parsed suppression directives for fast diagnostic filtering.
+     */
+    public static final class SuppressionIndex {
+        private final Set<String> fileSuppressed = new HashSet<>();
+        private final Map<Integer, Set<String>> lineSuppressed = new 
HashMap<>();
+        private boolean hasAnySuppression = false;
+
+        public boolean hasAnySuppression() {
+            return hasAnySuppression;
+        }
+
+        public boolean isSuppressed(Diagnostic d) {
+            if (d == null || !hasAnySuppression) {
+                return false;
+            }
+            if (!isSuppressibleSource(d.getSource())) {
+                return false;
+            }
+            String code = null;
+            if (d.getCode() != null) {
+                if (d.getCode().isLeft()) {
+                    code = d.getCode().getLeft();
+                } else if (d.getCode().isRight()) {
+                    code = String.valueOf(d.getCode().getRight());
+                }
+            }
+
+            if (matches(fileSuppressed, code)) {
+                return true;
+            }
+
+            if (d.getRange() != null && d.getRange().getStart() != null) {
+                int startLine = d.getRange().getStart().getLine();
+                if (matches(lineSuppressed.get(startLine), code)) {
+                    return true;
+                }
+                if (d.getRange().getEnd() != null) {
+                    int endLine = d.getRange().getEnd().getLine();
+                    if (endLine != startLine && 
matches(lineSuppressed.get(endLine), code)) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        private static boolean matches(Set<String> set, String code) {
+            if (set == null || set.isEmpty()) {
+                return false;
+            }
+            if (set.contains("*")) {
+                return true;
+            }
+            return code != null && set.contains(code.toLowerCase(Locale.ROOT));
+        }
+
+        public static SuppressionIndex parse(String text) {
+            SuppressionIndex index = new SuppressionIndex();
+            if (text == null || text.isEmpty()) {
+                return index;
+            }
+
+            // Quick check to bypass regex and line parsing if no directive 
namespace is present
+            if (!text.toLowerCase(Locale.ROOT).contains("@drl-lsp-lint:")) {
+                return index;
+            }
+
+            String codeText = DRLLintHelper.sanitize(text);
+            String[] codeLines = codeText.split("\r?\n", -1);
+            List<int[]> rules = findRuleBoundaries(codeLines);
+
+            String stringBlanked = blankStrings(text);
+            String[] lines = stringBlanked.split("\r?\n", -1);
+
+            Set<String> activeRegion = new HashSet<>();
+
+            for (int i = 0; i < lines.length; i++) {
+                String line = lines[i];
+                Matcher m = DIRECTIVE_PATTERN.matcher(line);
+
+                while (m.find()) {
+                    index.hasAnySuppression = true;
+                    String action = m.group(1).toLowerCase(Locale.ROOT);
+                    int argStart = m.end();
+
+                    int nextDirective = findNextDirective(line, argStart);
+                    String rawArgs = nextDirective >= 0
+                            ? line.substring(argStart, nextDirective)
+                            : line.substring(argStart);
+
+                    Set<String> codes = parseCodes(rawArgs);
+
+                    switch (action) {
+                        case "disable-file" -> 
index.fileSuppressed.addAll(codes);
+                        case "disable-line" -> index.lineSuppressed
+                                .computeIfAbsent(i, k -> new HashSet<>())
+                                .addAll(codes);
+                        case "disable-next-line" -> {
+                            if (i + 1 < lines.length) {

Review Comment:
   in a multi-line block comment this targets the `*/` line rather than the 
line after the comment



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);
+    }
+
+    /**
+     * Replaces string literal contents with spaces so directives inside quotes
+     * (e.g. {@code String s = "// @drl-lsp-lint:disable"}) are not treated as 
directives.
+     * Newlines are preserved to keep original line numbers intact.
+     */
+    static String blankStrings(String text) {
+        if (text == null || text.isEmpty()) {
+            return "";
+        }
+        char[] chars = text.toCharArray();
+        boolean inDouble = false;
+        boolean inSingle = false;
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+            if (c == '\n' || c == '\r') {
+                inDouble = false;
+                inSingle = false;
+                continue;
+            }
+            if (inDouble) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '"') {
+                    inDouble = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (inSingle) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '\'') {
+                    inSingle = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (c == '"') {
+                inDouble = true;
+            } else if (c == '\'') {
+                inSingle = true;
+            }
+        }
+        return new String(chars);
+    }
+
+    /**
+     * Index of parsed suppression directives for fast diagnostic filtering.
+     */
+    public static final class SuppressionIndex {
+        private final Set<String> fileSuppressed = new HashSet<>();
+        private final Map<Integer, Set<String>> lineSuppressed = new 
HashMap<>();
+        private boolean hasAnySuppression = false;
+
+        public boolean hasAnySuppression() {
+            return hasAnySuppression;
+        }
+
+        public boolean isSuppressed(Diagnostic d) {
+            if (d == null || !hasAnySuppression) {
+                return false;
+            }
+            if (!isSuppressibleSource(d.getSource())) {
+                return false;
+            }
+            String code = null;
+            if (d.getCode() != null) {
+                if (d.getCode().isLeft()) {
+                    code = d.getCode().getLeft();
+                } else if (d.getCode().isRight()) {
+                    code = String.valueOf(d.getCode().getRight());
+                }
+            }
+
+            if (matches(fileSuppressed, code)) {
+                return true;
+            }
+
+            if (d.getRange() != null && d.getRange().getStart() != null) {
+                int startLine = d.getRange().getStart().getLine();
+                if (matches(lineSuppressed.get(startLine), code)) {
+                    return true;
+                }
+                if (d.getRange().getEnd() != null) {
+                    int endLine = d.getRange().getEnd().getLine();
+                    if (endLine != startLine && 
matches(lineSuppressed.get(endLine), code)) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        private static boolean matches(Set<String> set, String code) {
+            if (set == null || set.isEmpty()) {
+                return false;
+            }
+            if (set.contains("*")) {
+                return true;
+            }
+            return code != null && set.contains(code.toLowerCase(Locale.ROOT));
+        }
+
+        public static SuppressionIndex parse(String text) {
+            SuppressionIndex index = new SuppressionIndex();
+            if (text == null || text.isEmpty()) {
+                return index;
+            }
+
+            // Quick check to bypass regex and line parsing if no directive 
namespace is present
+            if (!text.toLowerCase(Locale.ROOT).contains("@drl-lsp-lint:")) {
+                return index;
+            }
+
+            String codeText = DRLLintHelper.sanitize(text);
+            String[] codeLines = codeText.split("\r?\n", -1);
+            List<int[]> rules = findRuleBoundaries(codeLines);
+
+            String stringBlanked = blankStrings(text);
+            String[] lines = stringBlanked.split("\r?\n", -1);
+
+            Set<String> activeRegion = new HashSet<>();
+
+            for (int i = 0; i < lines.length; i++) {
+                String line = lines[i];
+                Matcher m = DIRECTIVE_PATTERN.matcher(line);
+
+                while (m.find()) {
+                    index.hasAnySuppression = true;
+                    String action = m.group(1).toLowerCase(Locale.ROOT);
+                    int argStart = m.end();
+
+                    int nextDirective = findNextDirective(line, argStart);
+                    String rawArgs = nextDirective >= 0
+                            ? line.substring(argStart, nextDirective)
+                            : line.substring(argStart);
+
+                    Set<String> codes = parseCodes(rawArgs);
+
+                    switch (action) {
+                        case "disable-file" -> 
index.fileSuppressed.addAll(codes);
+                        case "disable-line" -> index.lineSuppressed
+                                .computeIfAbsent(i, k -> new HashSet<>())
+                                .addAll(codes);
+                        case "disable-next-line" -> {
+                            if (i + 1 < lines.length) {
+                                index.lineSuppressed
+                                        .computeIfAbsent(i + 1, k -> new 
HashSet<>())
+                                        .addAll(codes);
+                            }
+                        }
+                        case "disable-rule" -> {
+                            int[] targetRule = findTargetRule(rules, i);
+                            if (targetRule != null) {
+                                for (int r = targetRule[0]; r <= targetRule[1] 
&& r < lines.length; r++) {
+                                    index.lineSuppressed
+                                            .computeIfAbsent(r, k -> new 
HashSet<>())
+                                            .addAll(codes);
+                                }
+                            }
+                        }
+                        case "disable" -> {
+                            if (codes.contains("*")) {
+                                activeRegion.clear();
+                                activeRegion.add("*");
+                            } else {
+                                activeRegion.addAll(codes);
+                            }
+                        }
+                        case "enable" -> {
+                            if (codes.contains("*")) {
+                                activeRegion.clear();
+                            } else {
+                                if (activeRegion.contains("*")) {
+                                    activeRegion.remove("*");
+                                    activeRegion.addAll(ALL_LINT_CODES);
+                                }
+                                activeRegion.removeAll(codes);
+                            }
+                        }
+                    }
+                }
+
+                if (!activeRegion.isEmpty()) {
+                    index.lineSuppressed
+                            .computeIfAbsent(i, k -> new HashSet<>())
+                            .addAll(activeRegion);
+                }
+            }
+
+            return index;
+        }
+
+        private static int findNextDirective(String line, int fromIndex) {
+            Matcher m = DIRECTIVE_PATTERN.matcher(line);
+            if (m.find(fromIndex)) {
+                return m.start();
+            }
+            return -1;
+        }
+
+        private static Set<String> parseCodes(String rawArgs) {
+            if (rawArgs == null) {
+                return Set.of("*");
+            }
+            int blockCommentEnd = rawArgs.indexOf("*/");
+            if (blockCommentEnd >= 0) {
+                rawArgs = rawArgs.substring(0, blockCommentEnd);
+            }
+            int commentSep = rawArgs.indexOf("--");
+            if (commentSep >= 0) {
+                rawArgs = rawArgs.substring(0, commentSep);
+            }
+            String trimmed = rawArgs.trim();
+            if (trimmed.isEmpty()) {
+                return Set.of("*");
+            }
+            Set<String> set = new HashSet<>();
+            String[] tokens = trimmed.split("[,\\s]+");
+            for (String t : tokens) {
+                String token = t.trim().toLowerCase(Locale.ROOT);
+                if (!token.isEmpty()) {
+                    set.add(token);
+                }
+            }
+            return set.isEmpty() ? Set.of("*") : set;
+        }
+
+        private static List<int[]> findRuleBoundaries(String[] codeLines) {
+            List<int[]> rules = new ArrayList<>();
+            boolean inDeclare = false;
+            int currentRuleStart = -1;
+
+            for (int i = 0; i < codeLines.length; i++) {
+                String trimmed = codeLines[i].trim();
+                if (trimmed.isEmpty()) {
+                    continue;
+                }
+                if (RULE_KEYWORD.matcher(trimmed).find()) {
+                    inDeclare = false;
+                    currentRuleStart = i;

Review Comment:
   this drops a rule that never got its `end`, so `disable-rule missing-end` 
above an unclosed rule ends up suppressing the next rule instead. 
`lintMissingRuleEnds` uses a stack for this



##########
packages/drools-lsp/drools-completion/src/test/java/org/drools/completion/DRLLintSuppressionTest.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4j.DiagnosticSeverity;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.lsp4j.Range;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class DRLLintSuppressionTest {
+
+    @AfterEach
+    void clearProperties() {
+        System.clearProperty("drools.lsp.lint.missingEnd");
+        System.clearProperty("drools.lsp.lint.missingSeparator");
+        System.clearProperty("drools.lsp.lint.missingSemicolon");
+        System.clearProperty("drools.lsp.lint.unbalancedParens");
+        System.clearProperty("drools.lsp.lint.unknownTypes");
+        System.clearProperty("drools.lsp.lint.mvelPropertyAccess");
+    }
+
+    @Test
+    void stableDiagnosticCodesAssigned() {
+        // Missing rule end
+        String missingEnd = "rule \"Unclosed\"\nwhen\nthen\n";
+        List<Diagnostic> endDiags = DRLLintHelper.lint(missingEnd);
+        assertThat(endDiags).hasSize(1);
+        
assertThat(endDiags.get(0).getCode().getLeft()).isEqualTo(DRLLintHelper.CODE_MISSING_END);
+
+        // Missing separator
+        String missingSep = "rule \"Sep\"\nwhen\n  Person(\n    name == 
\"A\"\n    age > 20\n  )\nthen\nend\n";
+        List<Diagnostic> sepDiags = DRLLintHelper.lint(missingSep);
+        assertThat(sepDiags).hasSize(1);
+        
assertThat(sepDiags.get(0).getCode().getLeft()).isEqualTo(DRLLintHelper.CODE_MISSING_SEPARATOR);
+
+        // Missing semicolon
+        String missingSemi = "rule \"Semi\"\nwhen\nthen\n  insert(new 
Person())\nend\n";
+        List<Diagnostic> semiDiags = DRLLintHelper.lint(missingSemi);
+        assertThat(semiDiags).hasSize(1);
+        
assertThat(semiDiags.get(0).getCode().getLeft()).isEqualTo(DRLLintHelper.CODE_MISSING_SEMICOLON);
+
+        // Unbalanced parens
+        String unclosedParen = "rule \"Paren\"\nwhen\n  Person( (age > 20 
)\nthen\nend\n";
+        List<Diagnostic> parenDiags = DRLLintHelper.lint(unclosedParen);
+        assertThat(parenDiags).hasSize(1);
+        
assertThat(parenDiags.get(0).getCode().getLeft()).isEqualTo(DRLLintHelper.CODE_UNBALANCED_PARENS);
+
+        // MVEL property access
+        System.setProperty("drools.lsp.lint.mvelPropertyAccess", "warning");
+        String mvel = "rule \"Mvel\"\nwhen\n  Person( getName() == \"John\" 
)\nthen\nend\n";
+        List<Diagnostic> mvelDiags = DRLLintHelper.lint(mvel);
+        assertThat(mvelDiags).hasSize(1);
+        
assertThat(mvelDiags.get(0).getCode().getLeft()).isEqualTo(DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS);
+    }
+
+    @Test
+    void disableFile_wildcardDropsAllLintDiagnostics() {
+        String text = "// @drl-lsp-lint:disable-file\n"
+                + "rule \"A\"\n"
+                + "when\n"
+                + "  Person(\n"
+                + "    name == \"A\"\n"
+                + "    age > 20\n"
+                + "  )\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).isEmpty();
+    }
+
+    @Test
+    void disableFile_specificCodeDropsOnlyTargetedDiagnostic() {
+        String text = "// @drl-lsp-lint:disable-file missing-semicolon\n"
+                + "rule \"A\"\n"
+                + "when\n"
+                + "  Person(\n"
+                + "    name == \"A\"\n"
+                + "    age > 20\n"
+                + "  )\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        
assertThat(diags.get(0).getCode().getLeft()).isEqualTo(DRLLintHelper.CODE_MISSING_SEPARATOR);
+    }
+
+    @Test
+    void disableFile_multipleCodes() {
+        String text = "// @drl-lsp-lint:disable-file missing-semicolon, 
missing-separator\n"
+                + "rule \"A\"\n"
+                + "when\n"
+                + "  Person(\n"
+                + "    name == \"A\"\n"
+                + "    age > 20\n"
+                + "  )\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).isEmpty();
+    }
+
+    @Test
+    void disableLine_wildcardDropsLineDiagnostics() {
+        String text = "rule \"A\"\n"
+                + "when\n"
+                + "then\n"
+                + "  insert(new Person()) // @drl-lsp-lint:disable-line\n"
+                + "  update(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        assertThat(diags.get(0).getRange().getStart().getLine()).isEqualTo(4);
+    }
+
+    @Test
+    void disableLine_specificCode() {
+        String text = "rule \"A\"\n"
+                + "when\n"
+                + "then\n"
+                + "  insert(new Person()) // @drl-lsp-lint:disable-line 
missing-semicolon\n"
+                + "  update(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        assertThat(diags.get(0).getRange().getStart().getLine()).isEqualTo(4);
+    }
+
+    @Test
+    void disableNextLine_wildcard() {
+        String text = "rule \"A\"\n"
+                + "when\n"
+                + "then\n"
+                + "  // @drl-lsp-lint:disable-next-line\n"
+                + "  insert(new Person())\n"
+                + "  update(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        assertThat(diags.get(0).getRange().getStart().getLine()).isEqualTo(5);
+    }
+
+    @Test
+    void disableNextLine_specificCode() {
+        String text = "rule \"A\"\n"
+                + "when\n"
+                + "then\n"
+                + "  // @drl-lsp-lint:disable-next-line missing-semicolon\n"
+                + "  insert(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).isEmpty();
+    }
+
+    @Test
+    void regionDisableAndEnable() {
+        String text = "// @drl-lsp-lint:disable missing-semicolon\n"
+                + "rule \"A\"\n"
+                + "when\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n"
+                + "// @drl-lsp-lint:enable missing-semicolon\n"
+                + "rule \"B\"\n"
+                + "when\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        assertThat(diags.get(0).getRange().getStart().getLine()).isEqualTo(10);
+    }
+
+    @Test
+    void disableRule_precedingComment() {
+        String text = "// @drl-lsp-lint:disable-rule missing-separator\n"
+                + "rule \"A\"\n"
+                + "when\n"
+                + "  Person(\n"
+                + "    name == \"A\"\n"
+                + "    age > 20\n"
+                + "  )\n"
+                + "then\n"
+                + "end\n"
+                + "rule \"B\"\n"
+                + "when\n"
+                + "  Person(\n"
+                + "    name == \"B\"\n"
+                + "    age > 30\n"
+                + "  )\n"
+                + "then\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        // Rule B's line should be flagged (line 12), Rule A was suppressed
+        assertThat(diags.get(0).getRange().getStart().getLine()).isEqualTo(12);
+    }
+
+    @Test
+    void disableRule_insideRule() {
+        String text = "rule \"A\"\n"
+                + "  // @drl-lsp-lint:disable-rule missing-semicolon\n"
+                + "when\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n"
+                + "rule \"B\"\n"
+                + "when\n"
+                + "then\n"
+                + "  insert(new Person())\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lint(text);
+        assertThat(diags).hasSize(1);
+        assertThat(diags.get(0).getRange().getStart().getLine()).isEqualTo(9);
+    }
+
+    @Test
+    void droolsType_unknownTypeSuppressed() {
+        String text = "// @drl-lsp-lint:disable-file unknown-type\n"
+                + "rule \"R\"\n"
+                + "when\n"
+                + "  NonExistentType()\n"
+                + "then\n"
+                + "end\n";
+
+        List<Diagnostic> diags = DRLLintHelper.lintUnknownTypes(text, null, 
Map.of(),
+                ClassIndex.empty(), ClassMemberIndex.empty(), true);
+        assertThat(diags).isEmpty();
+    }
+
+    @Test
+    void droolsType_unknownMemberSuppressed() {
+        String text = "rule \"R\"\n"
+                + "when\n"
+                + "  Person( nonExistentProp == 1 ) // 
@drl-lsp-lint:disable-line unknown-member\n"
+                + "then\n"
+                + "end\n";
+
+        Diagnostic memberDiag = new Diagnostic();
+        memberDiag.setSource("drools-type");
+        memberDiag.setCode(DRLLintHelper.CODE_UNKNOWN_MEMBER);
+        memberDiag.setRange(new Range(new Position(2, 10), new Position(2, 
25)));
+
+        List<Diagnostic> filtered = 
DRLLintSuppression.filter(List.of(memberDiag), text);
+        assertThat(filtered).isEmpty();
+    }
+
+    @Test
+    void parserAndCompilerDiagnosticsAreNeverSuppressed() {
+        String text = "// @drl-lsp-lint:disable-file\n"
+                + "rule \"SyntaxError\"\n";
+
+        Diagnostic syntaxDiag = new Diagnostic();
+        syntaxDiag.setSource("drools-drl-parser");
+        syntaxDiag.setMessage("mismatched input '<EOF>' expecting 'when'");
+        syntaxDiag.setRange(new Range(new Position(1, 0), new Position(1, 5)));
+
+        Diagnostic compileDiag = new Diagnostic();
+        compileDiag.setSource("drools");
+        compileDiag.setMessage("Rule compilation error");
+        compileDiag.setRange(new Range(new Position(1, 0), new Position(1, 
5)));
+
+        Diagnostic lintDiag = new Diagnostic();
+        lintDiag.setSource("drools-lint");
+        lintDiag.setCode(DRLLintHelper.CODE_MISSING_END);
+        lintDiag.setMessage("Missing 'end'");
+        lintDiag.setRange(new Range(new Position(1, 0), new Position(1, 4)));
+
+        List<Diagnostic> all = List.of(syntaxDiag, compileDiag, lintDiag);
+        List<Diagnostic> filtered = DRLLintSuppression.filter(all, text);
+
+        assertThat(filtered).containsExactly(syntaxDiag, compileDiag);
+    }
+
+    @Test
+    void alternateCommentSyntaxesAndDescriptions() {
+        // Hash comment
+        String hash = "# @drl-lsp-lint:disable-line missing-semicolon\n"

Review Comment:
   `#` isn't a comment in DRL10 though, the parser reports `mismatched input 
'#'` for this input. the test only passes because the lint doesn't parse, I'd 
drop `#` support



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");

Review Comment:
   `\b` matches between `disable` and `-`, so a typo like `disable-lines` turns 
into a `disable` region that runs to the end of the file. could we anchor the 
action and warn about unknown actions and codes? a misspelled code like 
`missing-semicolons` is accepted silently too



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);
+    }
+
+    /**
+     * Replaces string literal contents with spaces so directives inside quotes
+     * (e.g. {@code String s = "// @drl-lsp-lint:disable"}) are not treated as 
directives.
+     * Newlines are preserved to keep original line numbers intact.
+     */
+    static String blankStrings(String text) {
+        if (text == null || text.isEmpty()) {
+            return "";
+        }
+        char[] chars = text.toCharArray();
+        boolean inDouble = false;
+        boolean inSingle = false;
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+            if (c == '\n' || c == '\r') {
+                inDouble = false;
+                inSingle = false;
+                continue;
+            }
+            if (inDouble) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '"') {
+                    inDouble = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (inSingle) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '\'') {
+                    inSingle = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (c == '"') {
+                inDouble = true;
+            } else if (c == '\'') {
+                inSingle = true;
+            }
+        }
+        return new String(chars);
+    }
+
+    /**
+     * Index of parsed suppression directives for fast diagnostic filtering.
+     */
+    public static final class SuppressionIndex {
+        private final Set<String> fileSuppressed = new HashSet<>();
+        private final Map<Integer, Set<String>> lineSuppressed = new 
HashMap<>();
+        private boolean hasAnySuppression = false;
+
+        public boolean hasAnySuppression() {
+            return hasAnySuppression;
+        }
+
+        public boolean isSuppressed(Diagnostic d) {
+            if (d == null || !hasAnySuppression) {
+                return false;
+            }
+            if (!isSuppressibleSource(d.getSource())) {
+                return false;
+            }
+            String code = null;
+            if (d.getCode() != null) {
+                if (d.getCode().isLeft()) {
+                    code = d.getCode().getLeft();
+                } else if (d.getCode().isRight()) {
+                    code = String.valueOf(d.getCode().getRight());
+                }
+            }
+
+            if (matches(fileSuppressed, code)) {
+                return true;
+            }
+
+            if (d.getRange() != null && d.getRange().getStart() != null) {
+                int startLine = d.getRange().getStart().getLine();
+                if (matches(lineSuppressed.get(startLine), code)) {
+                    return true;
+                }
+                if (d.getRange().getEnd() != null) {
+                    int endLine = d.getRange().getEnd().getLine();
+                    if (endLine != startLine && 
matches(lineSuppressed.get(endLine), code)) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        private static boolean matches(Set<String> set, String code) {
+            if (set == null || set.isEmpty()) {
+                return false;
+            }
+            if (set.contains("*")) {
+                return true;
+            }
+            return code != null && set.contains(code.toLowerCase(Locale.ROOT));
+        }
+
+        public static SuppressionIndex parse(String text) {
+            SuppressionIndex index = new SuppressionIndex();
+            if (text == null || text.isEmpty()) {
+                return index;
+            }
+
+            // Quick check to bypass regex and line parsing if no directive 
namespace is present
+            if (!text.toLowerCase(Locale.ROOT).contains("@drl-lsp-lint:")) {
+                return index;
+            }
+
+            String codeText = DRLLintHelper.sanitize(text);
+            String[] codeLines = codeText.split("\r?\n", -1);
+            List<int[]> rules = findRuleBoundaries(codeLines);
+
+            String stringBlanked = blankStrings(text);
+            String[] lines = stringBlanked.split("\r?\n", -1);
+
+            Set<String> activeRegion = new HashSet<>();
+
+            for (int i = 0; i < lines.length; i++) {
+                String line = lines[i];
+                Matcher m = DIRECTIVE_PATTERN.matcher(line);
+
+                while (m.find()) {
+                    index.hasAnySuppression = true;
+                    String action = m.group(1).toLowerCase(Locale.ROOT);
+                    int argStart = m.end();
+
+                    int nextDirective = findNextDirective(line, argStart);
+                    String rawArgs = nextDirective >= 0
+                            ? line.substring(argStart, nextDirective)
+                            : line.substring(argStart);
+
+                    Set<String> codes = parseCodes(rawArgs);
+
+                    switch (action) {
+                        case "disable-file" -> 
index.fileSuppressed.addAll(codes);
+                        case "disable-line" -> index.lineSuppressed
+                                .computeIfAbsent(i, k -> new HashSet<>())
+                                .addAll(codes);
+                        case "disable-next-line" -> {
+                            if (i + 1 < lines.length) {
+                                index.lineSuppressed
+                                        .computeIfAbsent(i + 1, k -> new 
HashSet<>())
+                                        .addAll(codes);
+                            }
+                        }
+                        case "disable-rule" -> {
+                            int[] targetRule = findTargetRule(rules, i);
+                            if (targetRule != null) {
+                                for (int r = targetRule[0]; r <= targetRule[1] 
&& r < lines.length; r++) {
+                                    index.lineSuppressed
+                                            .computeIfAbsent(r, k -> new 
HashSet<>())
+                                            .addAll(codes);
+                                }
+                            }
+                        }
+                        case "disable" -> {
+                            if (codes.contains("*")) {
+                                activeRegion.clear();
+                                activeRegion.add("*");
+                            } else {
+                                activeRegion.addAll(codes);
+                            }
+                        }
+                        case "enable" -> {
+                            if (codes.contains("*")) {
+                                activeRegion.clear();
+                            } else {
+                                if (activeRegion.contains("*")) {
+                                    activeRegion.remove("*");
+                                    activeRegion.addAll(ALL_LINT_CODES);

Review Comment:
   any code that's not in `ALL_LINT_CODES` comes back inside the region here, 
so the deprecation codes would have to be added by hand. could the region be 
kept as "everything except the re-enabled codes" instead?



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);
+    }
+
+    /**
+     * Replaces string literal contents with spaces so directives inside quotes
+     * (e.g. {@code String s = "// @drl-lsp-lint:disable"}) are not treated as 
directives.
+     * Newlines are preserved to keep original line numbers intact.
+     */
+    static String blankStrings(String text) {
+        if (text == null || text.isEmpty()) {
+            return "";
+        }
+        char[] chars = text.toCharArray();
+        boolean inDouble = false;
+        boolean inSingle = false;
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+            if (c == '\n' || c == '\r') {
+                inDouble = false;
+                inSingle = false;
+                continue;
+            }
+            if (inDouble) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '"') {
+                    inDouble = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (inSingle) {
+                if (c == '\\' && i + 1 < chars.length) {
+                    chars[i] = ' ';
+                    chars[i + 1] = ' ';
+                    i++;
+                } else if (c == '\'') {
+                    inSingle = false;
+                } else {
+                    chars[i] = ' ';
+                }
+                continue;
+            }
+            if (c == '"') {
+                inDouble = true;
+            } else if (c == '\'') {
+                inSingle = true;
+            }
+        }
+        return new String(chars);
+    }
+
+    /**
+     * Index of parsed suppression directives for fast diagnostic filtering.
+     */
+    public static final class SuppressionIndex {
+        private final Set<String> fileSuppressed = new HashSet<>();
+        private final Map<Integer, Set<String>> lineSuppressed = new 
HashMap<>();
+        private boolean hasAnySuppression = false;
+
+        public boolean hasAnySuppression() {
+            return hasAnySuppression;
+        }
+
+        public boolean isSuppressed(Diagnostic d) {
+            if (d == null || !hasAnySuppression) {
+                return false;
+            }
+            if (!isSuppressibleSource(d.getSource())) {
+                return false;
+            }
+            String code = null;
+            if (d.getCode() != null) {
+                if (d.getCode().isLeft()) {
+                    code = d.getCode().getLeft();
+                } else if (d.getCode().isRight()) {
+                    code = String.valueOf(d.getCode().getRight());
+                }
+            }
+
+            if (matches(fileSuppressed, code)) {
+                return true;
+            }
+
+            if (d.getRange() != null && d.getRange().getStart() != null) {
+                int startLine = d.getRange().getStart().getLine();
+                if (matches(lineSuppressed.get(startLine), code)) {
+                    return true;
+                }
+                if (d.getRange().getEnd() != null) {
+                    int endLine = d.getRange().getEnd().getLine();
+                    if (endLine != startLine && 
matches(lineSuppressed.get(endLine), code)) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        private static boolean matches(Set<String> set, String code) {
+            if (set == null || set.isEmpty()) {
+                return false;
+            }
+            if (set.contains("*")) {
+                return true;
+            }
+            return code != null && set.contains(code.toLowerCase(Locale.ROOT));
+        }
+
+        public static SuppressionIndex parse(String text) {
+            SuppressionIndex index = new SuppressionIndex();
+            if (text == null || text.isEmpty()) {
+                return index;
+            }
+
+            // Quick check to bypass regex and line parsing if no directive 
namespace is present
+            if (!text.toLowerCase(Locale.ROOT).contains("@drl-lsp-lint:")) {
+                return index;
+            }
+
+            String codeText = DRLLintHelper.sanitize(text);
+            String[] codeLines = codeText.split("\r?\n", -1);
+            List<int[]> rules = findRuleBoundaries(codeLines);
+
+            String stringBlanked = blankStrings(text);
+            String[] lines = stringBlanked.split("\r?\n", -1);
+
+            Set<String> activeRegion = new HashSet<>();
+
+            for (int i = 0; i < lines.length; i++) {
+                String line = lines[i];
+                Matcher m = DIRECTIVE_PATTERN.matcher(line);
+
+                while (m.find()) {
+                    index.hasAnySuppression = true;
+                    String action = m.group(1).toLowerCase(Locale.ROOT);
+                    int argStart = m.end();
+
+                    int nextDirective = findNextDirective(line, argStart);
+                    String rawArgs = nextDirective >= 0
+                            ? line.substring(argStart, nextDirective)
+                            : line.substring(argStart);
+
+                    Set<String> codes = parseCodes(rawArgs);
+
+                    switch (action) {
+                        case "disable-file" -> 
index.fileSuppressed.addAll(codes);
+                        case "disable-line" -> index.lineSuppressed
+                                .computeIfAbsent(i, k -> new HashSet<>())
+                                .addAll(codes);
+                        case "disable-next-line" -> {
+                            if (i + 1 < lines.length) {
+                                index.lineSuppressed
+                                        .computeIfAbsent(i + 1, k -> new 
HashSet<>())
+                                        .addAll(codes);
+                            }
+                        }
+                        case "disable-rule" -> {
+                            int[] targetRule = findTargetRule(rules, i);
+                            if (targetRule != null) {
+                                for (int r = targetRule[0]; r <= targetRule[1] 
&& r < lines.length; r++) {
+                                    index.lineSuppressed
+                                            .computeIfAbsent(r, k -> new 
HashSet<>())
+                                            .addAll(codes);
+                                }
+                            }
+                        }
+                        case "disable" -> {
+                            if (codes.contains("*")) {
+                                activeRegion.clear();
+                                activeRegion.add("*");
+                            } else {
+                                activeRegion.addAll(codes);
+                            }
+                        }
+                        case "enable" -> {
+                            if (codes.contains("*")) {
+                                activeRegion.clear();
+                            } else {
+                                if (activeRegion.contains("*")) {
+                                    activeRegion.remove("*");
+                                    activeRegion.addAll(ALL_LINT_CODES);
+                                }
+                                activeRegion.removeAll(codes);
+                            }
+                        }
+                    }
+                }
+
+                if (!activeRegion.isEmpty()) {
+                    index.lineSuppressed
+                            .computeIfAbsent(i, k -> new HashSet<>())
+                            .addAll(activeRegion);
+                }
+            }
+
+            return index;
+        }
+
+        private static int findNextDirective(String line, int fromIndex) {
+            Matcher m = DIRECTIVE_PATTERN.matcher(line);
+            if (m.find(fromIndex)) {
+                return m.start();
+            }
+            return -1;
+        }
+
+        private static Set<String> parseCodes(String rawArgs) {
+            if (rawArgs == null) {

Review Comment:
   nit: `rawArgs` can't be null here, the `t.trim()` below does nothing after 
the split, and the `Collections` import is unused



##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintSuppression.java:
##########
@@ -0,0 +1,391 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.drools.completion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.lsp4j.Diagnostic;
+
+/**
+ * Parses in-source linter suppression directives under the {@code 
@drl-lsp-lint}
+ * namespace and filters out suppressed diagnostics.
+ *
+ * <p>Supported directives:
+ * <ul>
+ *   <li>{@code @drl-lsp-lint:disable-file [code, ...]} &mdash; suppresses 
matching codes (or all codes) for the entire file</li>
+ *   <li>{@code @drl-lsp-lint:disable-line [code, ...]} &mdash; suppresses 
matching codes on the current line</li>
+ *   <li>{@code @drl-lsp-lint:disable-next-line [code, ...]} &mdash; 
suppresses matching codes on the line immediately following</li>
+ *   <li>{@code @drl-lsp-lint:disable-rule [code, ...]} &mdash; suppresses 
matching codes for the entire enclosing or following rule</li>
+ *   <li>{@code @drl-lsp-lint:disable [code, ...]} &mdash; starts a 
suppression region from this line downwards</li>
+ *   <li>{@code @drl-lsp-lint:enable [code, ...]} &mdash; ends a suppression 
region from this line downwards</li>
+ * </ul>
+ *
+ * <p>Directives apply strictly to {@code drools-lint} and {@code drools-type}
+ * diagnostics. Parser/syntax errors ({@code drools-drl-parser}) and compiler
+ * diagnostics ({@code drools}) are never suppressed.
+ */
+public final class DRLLintSuppression {
+
+    private static final Pattern DIRECTIVE_PATTERN = Pattern.compile(
+            
"(?i)@drl-lsp-lint:(disable-file|disable-next-line|disable-line|disable-rule|disable|enable)\\b");
+
+    private static final Pattern RULE_KEYWORD =
+            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern DECLARE_KEYWORD =
+            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_START =
+            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+    private static final Pattern END_AT_END =
+            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+
+    public static final Set<String> ALL_LINT_CODES = Set.of(
+            DRLLintHelper.CODE_MISSING_END,
+            DRLLintHelper.CODE_MISSING_SEPARATOR,
+            DRLLintHelper.CODE_MISSING_SEMICOLON,
+            DRLLintHelper.CODE_UNBALANCED_PARENS,
+            DRLLintHelper.CODE_MVEL_PROPERTY_ACCESS,
+            DRLLintHelper.CODE_UNKNOWN_TYPE,
+            DRLLintHelper.CODE_UNKNOWN_MEMBER
+    );
+
+    private DRLLintSuppression() {
+    }
+
+    /**
+     * Filters {@code diagnostics} against any {@code @drl-lsp-lint} directives
+     * found in {@code text}. Diagnostics with sources other than {@code 
drools-lint}
+     * or {@code drools-type} are never dropped.
+     */
+    public static List<Diagnostic> filter(List<Diagnostic> diagnostics, String 
text) {
+        if (diagnostics == null || diagnostics.isEmpty() || text == null || 
text.isEmpty()) {
+            return diagnostics;
+        }
+        SuppressionIndex index = SuppressionIndex.parse(text);
+        if (!index.hasAnySuppression()) {
+            return diagnostics;
+        }
+        List<Diagnostic> filtered = new ArrayList<>(diagnostics.size());
+        for (Diagnostic d : diagnostics) {
+            if (!index.isSuppressed(d)) {
+                filtered.add(d);
+            }
+        }
+        return filtered;
+    }
+
+    /** Returns {@code true} if {@code source} is eligible for linter 
suppression. */
+    public static boolean isSuppressibleSource(String source) {
+        return "drools-lint".equals(source) || "drools-type".equals(source);
+    }
+
+    /**
+     * Replaces string literal contents with spaces so directives inside quotes
+     * (e.g. {@code String s = "// @drl-lsp-lint:disable"}) are not treated as 
directives.
+     * Newlines are preserved to keep original line numbers intact.
+     */
+    static String blankStrings(String text) {
+        if (text == null || text.isEmpty()) {
+            return "";
+        }
+        char[] chars = text.toCharArray();
+        boolean inDouble = false;
+        boolean inSingle = false;
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+            if (c == '\n' || c == '\r') {
+                inDouble = false;
+                inSingle = false;
+                continue;

Review Comment:
   agree, and the lexer already has comment tokens for this (`LINE_COMMENT`, 
and `RHS_LINE_COMMENT`/`RHS_COMMENT` inside consequences) with strings as 
separate tokens, so reading the directives from those would make `blankStrings` 
unnecessary. it would also stop `insert(p) @drl-lsp-lint:disable-line` written 
as plain code from counting



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to