Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support for TypeHierachy + CallHierarchy #612

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

angelozerr
Copy link
Contributor

feat: Support for TypeHierachy + CallHierarchy

@angelozerr
Copy link
Contributor Author

@InSyncWithFoo you can test this PR with your ls (see explanation at https://github.com/redhat-developer/lsp4ij?tab=readme-ov-file#testing-the-ci-builds)

It is working by default with TEXT and textmate language.

If you do Ctrl+Alt+H, it should execute the call hierarchy.

Here a sample with python:

image

If you have a custom language, you need to declare

<callHierarchyProvider
                language="YourLanguage"
                implementationClass="com.redhat.devtools.lsp4ij.features.callHierarchy.LSPCallHierarchyProvider" />

I have tested with the python code:

def calculate_subtotal(order):
    """
    Calculates the subtotal of the order.
    :param order: Dictionary with items and their prices.
    :return: Subtotal.
    """
    subtotal = sum(order.values())
    print(f"Calculated subtotal: {subtotal} €")
    return subtotal


def apply_discount(subtotal, discount):
    """
    Applies a discount to the subtotal.
    :param subtotal: Amount before the discount.
    :param discount: Discount percentage (0 to 100).
    :return: Amount after discount.
    """
    discounted_amount = subtotal * (1 - discount / 100)
    print(f"Discount applied ({discount}%): {discounted_amount} €")
    return discounted_amount


def calculate_tax(amount, tax_rate):
    """
    Calculates the tax on an amount.
    :param amount: Amount to which tax is applied.
    :param tax_rate: Tax rate percentage (e.g., 20 for 20%).
    :return: Tax amount.
    """
    tax = amount * (tax_rate / 100)
    print(f"Tax calculated ({tax_rate}%): {tax} €")
    return tax


def calculate_total(order, discount, tax_rate):
    """
    Calculates the total amount including discount and tax.
    :param order: Dictionary with items and their prices.
    :param discount: Discount percentage.
    :param tax_rate: Tax rate percentage.
    :return: Total amount.
    """
    subtotal = calculate_subtotal(order)
    discounted_amount = apply_discount(subtotal, discount)
    tax = calculate_tax(discounted_amount, tax_rate)
    total = discounted_amount + tax
    print(f"Total amount: {total} €")
    return total


# Example usage
if __name__ == "__main__":
    order_example = {
        "Burger": 10.99,
        "Fries": 4.50,
        "Drink": 2.00
    }
    discount_rate = 10  # 10% discount
    tax_rate = 20       # 20% tax

    total_amount = calculate_total(order_example, discount_rate, tax_rate)
    print(f"Final total: {total_amount} €")

@angelozerr
Copy link
Contributor Author

@InSyncWithFoo please give me feedback. I would like tointegrate in 0.8.0 since bydefault it is working with TEXT and textmate language (no impact for other languages).

@angelozerr angelozerr added this to the 0.8.0 milestone Nov 22, 2024
@InSyncWithFoo
Copy link
Contributor

I'm in the middle of publishing a long-awaited release, so I'll be testing the build and giving you feedbacks on Monday.

@angelozerr
Copy link
Contributor Author

Ok thanks.

After doing a lot of tests, it seems it is working good.

I need to write docs and after that I will merge my PR.

If you have time to test it is nice otherwise I will create the release on monday.

@angelozerr angelozerr force-pushed the lsp_hierarchy branch 3 times, most recently from 429bfa1 to af58724 Compare November 23, 2024 11:30
@angelozerr angelozerr marked this pull request as ready for review November 23, 2024 11:44
@angelozerr
Copy link
Contributor Author

Another test with go:

package main

import "fmt"

// Main function
func main() {
	fmt.Println("Program started.")

	// Call the first function
	firstFunction()

	fmt.Println("Program ended.")
}

// First function
func firstFunction() {
	fmt.Println("Inside firstFunction.")

	// Call secondFunction
	secondFunction("Hello from firstFunction!")
}

// Second function
func secondFunction(message string) {
	fmt.Println("Inside secondFunction.")
	fmt.Println("Message received:", message)

	// Call thirdFunction with a number
	result := thirdFunction(5)
	fmt.Println("Result from thirdFunction:", result)
}

// Third function
func thirdFunction(n int) int {
	fmt.Println("Inside thirdFunction. Input:", n)

	// Perform a calculation and call fourthFunction
	result := n * n
	fmt.Println("Calculated square:", result)

	// Call fourthFunction with the result
	return fourthFunction(result)
}

// Fourth function
func fourthFunction(x int) int {
	fmt.Println("Inside fourthFunction. Input:", x)

	// Perform another calculation
	double := x * 2
	fmt.Println("Doubled value:", double)

	// Call fifthFunction with the doubled value
	fifthFunction(double)
	return double
}

// Fifth function
func fifthFunction(finalValue int) {
	fmt.Println("Inside fifthFunction. Final value received:", finalValue)

	// End the chain
	if finalValue > 50 {
		fmt.Println("The final value is too large!")
	} else {
		fmt.Println("The final value is acceptable.")
	}
}

image

@angelozerr angelozerr merged commit 50561a2 into redhat-developer:main Nov 23, 2024
6 checks passed
@angelozerr angelozerr self-assigned this Nov 23, 2024
This was referenced Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants