import { syntaxTree } from '@codemirror/language';
import { Localized } from '../../editor';
import { unsupported } from '../keywords';
import { checkValidIdentifier, getCheckContext } from '../utils/check-identifier';
import { getCodeName } from '../utils/code';
// UnsupportedLinter: Checks for unsupported primitives
// Important note: anything with a colon and no supported extension is tokenized as
// 'UnsupportedPrim', so acceptable uses of variable names that include colons need
// to be filtered out here
export const UnsupportedLinter = (view, preprocessContext, lintContext) => {
    const diagnostics = [];
    const context = getCheckContext(view, lintContext, preprocessContext);
    let indices = [];
    syntaxTree(view.state)
        .cursor()
        .iterate((node) => {
        var _a, _b, _c, _d, _e;
        if (indices.includes(node.from))
            return;
        const value = getCodeName(view.state, node);
        // Unsupported primitives are always linted - they are reserved anyway
        if (unsupported.includes(value)) {
            indices.push(node.from);
            diagnostics.push({
                from: node.from,
                to: node.to,
                severity: 'warning',
                message: Localized.Get('Unsupported statement _', value),
            });
        }
        // Otherwise, there could be a extension-like identifier that we need to rule out
        if (node.name.includes('Unsupported') &&
            ((_a = node.node.parent) === null || _a === void 0 ? void 0 : _a.name) != 'VariableName' &&
            ((_b = node.node.parent) === null || _b === void 0 ? void 0 : _b.name) != 'NewVariableDeclaration' &&
            ((_c = node.node.parent) === null || _c === void 0 ? void 0 : _c.name) != 'Arguments' &&
            ((_d = node.node.parent) === null || _d === void 0 ? void 0 : _d.name) != 'AnonArguments' &&
            ((_e = node.node.parent) === null || _e === void 0 ? void 0 : _e.name) != 'ProcedureName' &&
            !checkValidIdentifier(node.node, value, context)) {
            indices.push(node.from);
            diagnostics.push({
                from: node.from,
                to: node.to,
                severity: 'warning',
                message: Localized.Get('Unsupported extension statement _', value),
            });
        }
    });
    return diagnostics;
};
//# sourceMappingURL=unsupported-linter.js.map