Code review comment: Then shall we add separate util to accept the line?

Code under review:
public Object execute(ExecuteCommandContext context) throws LSCommandExecutorException {
        String uri = null;
        Range range = null;
        for (CommandArgument arg : context.getArguments()) {
            switch (arg.key()) {
                case CommandConstants.ARG_KEY_DOC_URI:
                    uri = arg.valueAs(String.class);
                    break;
                case CommandConstants.ARG_KEY_NODE_RANGE:
                    range = arg.valueAs(Range.class);
                    break;
                default:
            }
        }

        Optional<Path> filePath = CommonUtil.getPathFromURI(uri);
        if (range == null || filePath.isEmpty()) {
            throw new UserErrorException("Invalid parameters received for the create function command!");
        }

        SyntaxTree syntaxTree = context.workspace().syntaxTree(filePath.get()).orElseThrow();
        NonTerminalNode cursorNode = CommonUtil.findNode(range, syntaxTree);

        if (cursorNode == null) {
            return Collections.emptyList();
        }

        Optional<FunctionCallExpressionNode> fnCallExprNode =
                CreateFunctionCodeAction.checkAndGetFunctionCallExpressionNode(cursorNode);
        if (fnCallExprNode.isEmpty()) {
            return new UserErrorException("Couldn't find a matching node");
        }

        SemanticModel semanticModel = context.workspace().semanticModel(filePath.get()).orElseThrow();

        LineRange rootLineRange = syntaxTree.rootNode().lineRange();
        int endLine = rootLineRange.endLine().line() + 1;
        int endCol = 0;
        
        boolean newLineAtEnd = rootLineRange.endLine().offset() == 0;

        Set<String> visibleSymbolNames = context.visibleSymbols(filePath.get(), new Position(endLine, endCol))
                .stream()
                .map(Symbol::getName)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .collect(Collectors.toSet());

        DocumentServiceContext docServiceContext = ContextBuilder.buildDocumentServiceContext(
                uri,
                context.workspace(),
                LSContextOperation.WS_EXEC_CMD,
                context.languageServercontext());

        List<String> args = new ArrayList<>();
        int argIndex = 1;
        List<SymbolKind> argumentKindList = Arrays.asList(SymbolKind.VARIABLE, SymbolKind.CONSTANT);
        for (FunctionArgumentNode fnArgNode : fnCallExprNode.get().arguments()) {
            Optional<TypeSymbol> type = semanticModel.typeOf(fnArgNode);
            Optional<Symbol> symbol;
            if (fnArgNode.kind() == SyntaxKind.POSITIONAL_ARG) {
                symbol = semanticModel.symbol(((PositionalArgumentNode) fnArgNode).expression());
            } else {
                symbol = semanticModel.symbol(fnArgNode);
            }
            String varName = "";
            if (symbol.isPresent() && argumentKindList.contains(symbol.get().kind())) {
                varName = symbol.get().getName().orElse("");
            }

            if (type.isPresent() && type.get().typeKind() != TypeDescKind.COMPILATION_ERROR) {
                varName = CommonUtil.generateParameterName(varName, argIndex,
                        CommonUtil.getRawType(type.get()), visibleSymbolNames);
                args.add(FunctionGenerator.getParameterTypeAsString(docServiceContext, type.get()) + " " + varName);
            } else {
                varName = CommonUtil.generateParameterName(varName, argIndex, null, visibleSymbolNames);
                args.add(FunctionGenerator.getParameterTypeAsString(docServiceContext, null) + " " + varName);
            }
            visibleSymbolNames.add(varName);
            argIndex++;
        }

        if (fnCallExprNode.get().functionName().kind() != SyntaxKind.SIMPLE_NAME_REFERENCE) {
            return Collections.emptyList();
        }

        String functionName = ((SimpleNameReferenceNode) fnCallExprNode.get().functionName()).name().text();
        if (functionName.isEmpty()) {
            return Collections.emptyList();
        }

        LanguageClient client = context.getLanguageClient();
        List<TextEdit> edits = new ArrayList<>();
        Optional<NonTerminalNode> enclosingNode = findEnclosingModulePartNode(fnCallExprNode.get());
        Range insertRange;
        if (enclosingNode.isPresent()) {
            LineRange lineRange = enclosingNode.get().lineRange();
            newLineAtEnd = addNewLineAtEnd(enclosingNode.get());
            insertRange = new Range(new Position(lineRange.endLine().line(), lineRange.endLine().offset()),
                    new Position(lineRange.endLine().line(), lineRange.endLine().offset()));
        } else {
            insertRange = new Range(new Position(endLine, endCol), new Position(endLine, endCol));
        }

        FunctionCallExpressionTypeFinder typeFinder = new FunctionCallExpressionTypeFinder(semanticModel);
        typeFinder.findTypeOf(fnCallExprNode.get());
        Optional<TypeSymbol> returnTypeSymbol = typeFinder.getReturnTypeSymbol();
        Optional<TypeDescKind> returnTypeDescKind = typeFinder.getReturnTypeDescKind();

        
        IsolatedBlockResolver isolatedBlockResolver = new IsolatedBlockResolver();
        Boolean isIsolated = isolatedBlockResolver.findIsolatedBlock(fnCallExprNode.get());

        
        
        String function;
        if (returnTypeSymbol.isPresent()) {
            function = FunctionGenerator.generateFunction(docServiceContext, newLineAtEnd, functionName,
                    args, returnTypeSymbol.get(), isIsolated);
        } else if (returnTypeDescKind.isPresent()) {
            function = FunctionGenerator.generateFunction(docServiceContext, newLineAtEnd, functionName,
                    args, returnTypeDescKind.get(), isIsolated);
        } else {
            return Collections.emptyList();
        }

        edits.add(new TextEdit(insertRange, function));
        TextDocumentEdit textDocumentEdit = new TextDocumentEdit(new VersionedTextDocumentIdentifier(uri, null), edits);
        return CommandUtil.applyWorkspaceEdit(Collections.singletonList(Either.forLeft(textDocumentEdit)), client);
    }

Line commented on: new Position(lineRange.endLine().line(), lineRange.endLine().offset()));

Revised code:
public Object execute(ExecuteCommandContext context) throws LSCommandExecutorException {
        String uri = null;
        Range range = null;
        for (CommandArgument arg : context.getArguments()) {
            switch (arg.key()) {
                case CommandConstants.ARG_KEY_DOC_URI:
                    uri = arg.valueAs(String.class);
                    break;
                case CommandConstants.ARG_KEY_NODE_RANGE:
                    range = arg.valueAs(Range.class);
                    break;
                default:
            }
        }

        Optional<Path> filePath = CommonUtil.getPathFromURI(uri);
        if (range == null || filePath.isEmpty()) {
            throw new UserErrorException("Invalid parameters received for the create function command!");
        }

        SyntaxTree syntaxTree = context.workspace().syntaxTree(filePath.get()).orElseThrow();
        NonTerminalNode cursorNode = CommonUtil.findNode(range, syntaxTree);

        if (cursorNode == null) {
            return Collections.emptyList();
        }

        Optional<FunctionCallExpressionNode> fnCallExprNode =
                CreateFunctionCodeAction.checkAndGetFunctionCallExpressionNode(cursorNode);
        if (fnCallExprNode.isEmpty()) {
            return new UserErrorException("Couldn't find a matching node");
        }

        SemanticModel semanticModel = context.workspace().semanticModel(filePath.get()).orElseThrow();

        LineRange rootLineRange = syntaxTree.rootNode().lineRange();
        int endLine = rootLineRange.endLine().line() + 1;
        int endCol = 0;
        
        boolean newLineAtEnd = rootLineRange.endLine().offset() == 0;

        Set<String> visibleSymbolNames = context.visibleSymbols(filePath.get(), new Position(endLine, endCol))
                .stream()
                .map(Symbol::getName)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .collect(Collectors.toSet());

        DocumentServiceContext docServiceContext = ContextBuilder.buildDocumentServiceContext(
                uri,
                context.workspace(),
                LSContextOperation.WS_EXEC_CMD,
                context.languageServercontext());

        List<String> args = new ArrayList<>();
        int argIndex = 1;
        List<SymbolKind> argumentKindList = Arrays.asList(SymbolKind.VARIABLE, SymbolKind.CONSTANT);
        for (FunctionArgumentNode fnArgNode : fnCallExprNode.get().arguments()) {
            Optional<TypeSymbol> type = semanticModel.typeOf(fnArgNode);
            Optional<Symbol> symbol;
            if (fnArgNode.kind() == SyntaxKind.POSITIONAL_ARG) {
                symbol = semanticModel.symbol(((PositionalArgumentNode) fnArgNode).expression());
            } else {
                symbol = semanticModel.symbol(fnArgNode);
            }
            String varName = "";
            if (symbol.isPresent() && argumentKindList.contains(symbol.get().kind())) {
                varName = symbol.get().getName().orElse("");
            }

            if (type.isPresent() && type.get().typeKind() != TypeDescKind.COMPILATION_ERROR) {
                varName = CommonUtil.generateParameterName(varName, argIndex,
                        CommonUtil.getRawType(type.get()), visibleSymbolNames);
                args.add(FunctionGenerator.getParameterTypeAsString(docServiceContext, type.get()) + " " + varName);
            } else {
                varName = CommonUtil.generateParameterName(varName, argIndex, null, visibleSymbolNames);
                args.add(FunctionGenerator.getParameterTypeAsString(docServiceContext, null) + " " + varName);
            }
            visibleSymbolNames.add(varName);
            argIndex++;
        }

        if (fnCallExprNode.get().functionName().kind() != SyntaxKind.SIMPLE_NAME_REFERENCE) {
            return Collections.emptyList();
        }

        String functionName = ((SimpleNameReferenceNode) fnCallExprNode.get().functionName()).name().text();
        if (functionName.isEmpty()) {
            return Collections.emptyList();
        }

        LanguageClient client = context.getLanguageClient();
        List<TextEdit> edits = new ArrayList<>();
        Optional<NonTerminalNode> enclosingNode = findEnclosingModulePartNode(fnCallExprNode.get());
        Range insertRange;
        if (enclosingNode.isPresent()) {
            newLineAtEnd = addNewLineAtEnd(enclosingNode.get());
            insertRange = CommonUtil.toRange(enclosingNode.get().lineRange().endLine());
        } else {
            insertRange = new Range(new Position(endLine, endCol), new Position(endLine, endCol));
        }

        FunctionCallExpressionTypeFinder typeFinder = new FunctionCallExpressionTypeFinder(semanticModel);
        typeFinder.findTypeOf(fnCallExprNode.get());
        Optional<TypeSymbol> returnTypeSymbol = typeFinder.getReturnTypeSymbol();
        Optional<TypeDescKind> returnTypeDescKind = typeFinder.getReturnTypeDescKind();

        
        IsolatedBlockResolver isolatedBlockResolver = new IsolatedBlockResolver();
        Boolean isIsolated = isolatedBlockResolver.findIsolatedBlock(fnCallExprNode.get());

        
        
        String function;
        if (returnTypeSymbol.isPresent()) {
            function = FunctionGenerator.generateFunction(docServiceContext, newLineAtEnd, functionName,
                    args, returnTypeSymbol.get(), isIsolated);
        } else if (returnTypeDescKind.isPresent()) {
            function = FunctionGenerator.generateFunction(docServiceContext, newLineAtEnd, functionName,
                    args, returnTypeDescKind.get(), isIsolated);
        } else {
            return Collections.emptyList();
        }

        edits.add(new TextEdit(insertRange, function));
        TextDocumentEdit textDocumentEdit = new TextDocumentEdit(new VersionedTextDocumentIdentifier(uri, null), edits);
        return CommandUtil.applyWorkspaceEdit(Collections.singletonList(Either.forLeft(textDocumentEdit)), client);
    }