private CodeAction fixDeprecatedTokenAttributeOrIndex(EventCodeActionContext context, Diagnostic diagnostic, DiagnosticCode code) {
        // TODO: actually create an enclosing schema if it doesn't exist?
        if (!context.document.getRootNode().get(0).isASTInstance(rootSchema.class)) return null;

        Class<? extends ai.vespa.schemals.parser.Node> offendingBodyClass;
        String replacementKind;

        if (code == DiagnosticCode.DEPRECATED_TOKEN_ATTRIBUTE) {
            offendingBodyClass = attributeElm.class;
            replacementKind = "attribute";
        } else {
            offendingBodyClass = indexInsideField.class;
            replacementKind = "index";
        }

        Node offendingNode = CSTUtils.getNodeAtPosition(context.document.getRootNode(), context.position);

        // Find the field definition containing the error as well as its data type
        Optional<Symbol> fieldDefinition = CSTUtils.findScope(offendingNode);
        if (fieldDefinition.isEmpty()) return null;

        Optional<Node> dataTypeNode = context.schemaIndex.fieldIndex().getFieldDataTypeNode(fieldDefinition.get());

        // use some arbitrary default, the generated field will most likely require manual editing anyways
        String dataTypeString = dataTypeNode.isPresent() ? dataTypeNode.get().getText() : "string"; 

        // Find the node containing the entire index or attribute statement
        Node offendingBodyElmNode = offendingNode;
        while (offendingBodyElmNode != null && !offendingBodyElmNode.isASTInstance(offendingBodyClass)) {
            offendingBodyElmNode = offendingBodyElmNode.getParent();
        }
        if (offendingBodyElmNode == null) return null;

        // Find the rootSchemaItemNode containing the document so we can insert after
        Node rootSchemaItemNode = findRootSchemaItemNode(offendingNode);
        if (rootSchemaItemNode == null) return null;


        // Calculate required indent and insert position
        String insertIndentString = StringUtils.getIndentString(context.document.getCurrentContent(), rootSchemaItemNode);
        int indent = StringUtils.countSpaceIndents(insertIndentString);
        Range insertPosition = new Range(rootSchemaItemNode.getRange().getEnd(), rootSchemaItemNode.getRange().getEnd());


        // subtract indent from the index/attribute block to match the new indent outside document
        String offendingBodyIndentString = StringUtils.getIndentString(context.document.getCurrentContent(), offendingBodyElmNode);
        int bodyIndentDelta = indent + StringUtils.TAB_SIZE - StringUtils.countSpaceIndents(offendingBodyIndentString);
        String offendingBodyText = StringUtils.addIndents(
            offendingBodyElmNode.getText().replace("\t", StringUtils.spaceIndent(StringUtils.TAB_SIZE)),
            bodyIndentDelta
        );

        CodeAction action = basicQuickFix("Create field '" + offendingNode.getText() + "' outside document", diagnostic);
        action.setEdit(CodeActionUtils.simpleEditList(context, List.of(
            new TextEdit(offendingBodyElmNode.getRange(), ""),
            new TextEdit(insertPosition, "\n" + StringUtils.spaceIndent(indent) +
                "field " + offendingNode.getText() + " type " + dataTypeString + " {\n" +
                StringUtils.spaceIndent(indent + StringUtils.TAB_SIZE) + "# TODO: Auto-generated indexing statement\n" +
                // Fields outside document needs an indexing statement to be useful
                StringUtils.spaceIndent(indent + StringUtils.TAB_SIZE) + "indexing: input " + fieldDefinition.get().getShortIdentifier() + " | " + replacementKind + "\n" +
                StringUtils.spaceIndent(indent + StringUtils.TAB_SIZE) + offendingBodyText + "\n" + 
                StringUtils.spaceIndent(indent) + "}")
        )));

        action.setIsPreferred(true);

        return action;
    }
Quick fix for using attribute some_name_other_than_field_name in a field. Will create a new field outside 
the document with the specified attribute, using the original field as input and type.
@param context
@param diagnostic
@param code
@return CodeAction supplying the edits.
integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/lsp/schema/codeaction/provider/QuickFixProvider.java