nvimdev / lspsaga.nvim

improve neovim lsp experience
MIT License
3.43k stars 284 forks source link

winbar is missing class methods #445

Closed RAV64 closed 2 years ago

RAV64 commented 2 years ago

Description

Setting up winbar doesn't show which class method I'm in.

Expected Behavior Winbar shows which class method I'm in.

Actual Behavior I can't see which method I'm in but I can see for example class>variable(which is inside a method) so it should show class>method>variable

Everything works as expected

image

Still everything is ok

image

init is missing from the chain

image

Details

Reproduce ```local status, lspsaga = pcall(require, "lspsaga") if not status then print("ERROR: lspsaga") return end local kind = require("lspsaga.lspkind") kind[1][2] = " " kind[2][2] = " " kind[5][2] = "ﴯ " kind[6][2] = " " kind[7][2] = "ﰠ " kind[9][2] = " " kind[11][2] = " " kind[12][2] = " " kind[13][2] = " " kind[14][2] = " " kind[15][2] = " " kind[16][2] = " " kind[20][2] = " " kind[22][2] = " " lspsaga.init_lsp_saga({ symbol_in_winbar = { in_custom = true, enable = true, separator = " > " }, max_preview_lines = 20, finder_action_keys = { open = "", vsplit = "s", split = "w", tabe = "t", quit = { "q", "" }, scroll_down = "", scroll_up = "", }, }) local function get_file_name(include_path) local file_name = require("lspsaga.symbolwinbar").get_file_name() if vim.fn.bufname("%") == "" then return "" end if include_path == false then return file_name end -- Else if include path: ./lsp/saga.lua -> lsp > saga.lua local sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/" local path_list = vim.split(string.gsub(vim.fn.expand("%:~:.:h"), "%%", ""), sep) local file_path = "" for _, cur in ipairs(path_list) do file_path = (cur == "." or cur == "~") and "" or file_path .. cur .. "%#LspSagaWinbarSep#/%*" .. "%*" end return file_path .. file_name end local function config_winbar() local exclude = { ["teminal"] = true, ["toggleterm"] = true, ["prompt"] = true, ["NvimTree"] = true, ["help"] = true, } -- Ignore float windows and exclude filetype if vim.api.nvim_win_get_config(0).zindex or exclude[vim.bo.filetype] then vim.wo.winbar = "" else local ok, lspsaga_symbolwinbar = pcall(require, "lspsaga.symbolwinbar") local sym if ok then sym = lspsaga_symbolwinbar.get_symbol_node() end local win_val = "" win_val = get_file_name(true) -- set to true to include path if sym ~= nil then win_val = win_val .. sym end vim.wo.winbar = win_val end end local events = { "BufEnter", "BufWinEnter", "CursorMoved" } vim.api.nvim_create_autocmd(events, { pattern = "*", callback = function() config_winbar() end, }) vim.api.nvim_create_autocmd("User", { pattern = "LspsagaUpdateSymbol", callback = function() config_winbar() end, }) ```
Environment - nvim --version output: NVIM v0.8.0-dev-nightly-1206-g1ef84547a - Operating system: macOS Monterey M1 12.5 - lspsaga commit: latest [bd95871](https://github.com/glepnir/lspsaga.nvim/commit/bd95871d67b8942a7869f8284c151b85f653027b)
glepnir commented 2 years ago

@RAV64 please test version_2 branch

RAV64 commented 2 years ago

@glepnir same problem!

glepnir commented 2 years ago

hmm but I got the init .

RAV64 commented 2 years ago

What can I check to try to find out the reason its missing for me?

glepnir commented 2 years ago

image

glepnir commented 2 years ago

but first_run is missed ..maybe still something wrong.

glepnir commented 2 years ago

can you update and test it?

RAV64 commented 2 years ago

Same behaviour as in my earlier images, branch version_2, newest commit.

glepnir commented 2 years ago

fixed

RAV64 commented 2 years ago

Still same behaviour on my nvim!

RAV64 commented 2 years ago

Also other methods don't get any recognition:

image
glepnir commented 2 years ago

post your python code here

RAV64 commented 2 years ago
Code here ``` import json import os from datetime import datetime, timedelta from time import sleep import concurrent.futures import numpy as np from binance.client import Client from helpers.parameters import load_config from helpers.handle_creds import load_correct_creds, load_telegram_creds from helpers.logger import Logger class FreeMoney: def __init__(self): self.first_run = True self.session_profit_percent = 0 self.session_profit_amount = 0 self.data_collected = False self.prices = {} self.collected_starting_data = False self.update_check = False parsed_config = load_config("config.yml") parsed_creds = load_config("creds.yml") ACCESS_KEY, SECRET_KEY = load_correct_creds(parsed_creds) TELEGRAM_CHANNEL_ID, TELEGRAM_TOKEN = load_telegram_creds(parsed_creds) self.TEST_MODE = parsed_config["script_options"]["TEST_MODE"] self.CUSTOM_LIST = parsed_config["trading_options"]["CUSTOM_LIST"] TELEGRAM_LOGGING = parsed_config["script_options"]["TELEGRAM_LOGGING"] LOG_FILE = parsed_config["script_options"]["LOG_FILE"] TICKERS_LIST = parsed_config["trading_options"]["TICKERS_LIST"] self.DEBUG = parsed_config["script_options"]["DEBUG"] self.PAIR_WITH = parsed_config["trading_options"]["PAIR_WITH"] self.QUANTITY = parsed_config["trading_options"]["QUANTITY"] self.MAX_COINS = parsed_config["trading_options"]["MAX_COINS"] self.FIATS = parsed_config["trading_options"]["FIATS"] self.TIME_DIFFERENCE = parsed_config["trading_options"]["TIME_DIFFERENCE"] / 60 self.RECHECK_INTERVAL = parsed_config["trading_options"]["RECHECK_INTERVAL"] self.CHANGE_IN_PRICE = parsed_config["trading_options"]["CHANGE_IN_PRICE"] self.STOP_LOSS = parsed_config["trading_options"]["STOP_LOSS"] self.TAKE_PROFIT = parsed_config["trading_options"]["TAKE_PROFIT"] self.TRAILING_STOP_LOSS = parsed_config["trading_options"]["TRAILING_STOP_LOSS"] self.TRAILING_TAKE_PROFIT = parsed_config["trading_options"][ "TRAILING_TAKE_PROFIT" ] self.SIGNALLING_MODULES = parsed_config["trading_options"]["SIGNALLING_MODULES"] self.TRADING_FEE = parsed_config["trading_options"]["TRADING_FEE"] self.client = Client(ACCESS_KEY, SECRET_KEY) self.log = Logger( TELEGRAM_CHANNEL_ID, TELEGRAM_TOKEN, TELEGRAM_LOGGING, LOG_FILE ).log if not self.TEST_MODE: self.coins_bought_file_path = "files/coins_bought.json" print("Using main net! Bot will activate in 10 seconds.") sleep(10) else: self.coins_bought_file_path = "files/test_coins_bought.json" print("Using test net!") if ( os.path.isfile(self.coins_bought_file_path) and os.stat(self.coins_bought_file_path).st_size != 0 ): with open(self.coins_bought_file_path) as file: self.coins_bought = json.load(file) else: self.coins_bought = {} if self.CUSTOM_LIST: self.tickers = [line.strip() for line in open("files/" + TICKERS_LIST)] self.starting_time = datetime.now() self.time_tracker = datetime.now() while True: self.get_prices() def get_prices(self): if self.first_run: coins = self.client.get_all_tickers() for coin in coins: if any( item + self.PAIR_WITH == coin["symbol"] for item in self.tickers ) and all(item not in coin["symbol"] for item in self.FIATS): self.prices[coin["symbol"]] = { "price": [float(coin["price"])], "time": [datetime.now()], } self.first_run = False if self.time_tracker <= datetime.now() - timedelta( minutes=float(self.TIME_DIFFERENCE / self.RECHECK_INTERVAL) ): coins = self.client.get_all_tickers() self.update_portfolio() for coin in coins: if any( item + self.PAIR_WITH == coin["symbol"] for item in self.tickers ) and all(item not in coin["symbol"] for item in self.FIATS): self.prices[coin["symbol"]]["price"].append(float(coin["price"])) self.prices[coin["symbol"]]["time"].append( datetime.now().timestamp() ) if self.collected_starting_data: self.prices[coin["symbol"]]["price"].pop(0) self.prices[coin["symbol"]]["time"].pop(0) if not self.collected_starting_data: print( len(self.prices["BTCUSDT"]["price"]), "/", self.RECHECK_INTERVAL, end="\r", ) if len(self.prices["BTCUSDT"]["price"]) == self.RECHECK_INTERVAL: print("Starting data collected!") self.collected_starting_data = True self.time_tracker = datetime.now() if self.collected_starting_data: self.sell_buy_check() def sell(self, coin): PriceChange = float( (self.prices[coin]["price"][-1] - self.coins_bought[coin]["bought_at"]) / self.coins_bought[coin]["bought_at"] * 100 ) if not self.TEST_MODE: try: self.client.create_order( symbol=coin, side="SELL", type="MARKET", quantity=self.coins_bought[coin]["volume"], ) except Exception as e: print(e) profit = ( (self.prices[coin]["price"][-1] - self.coins_bought[coin]["bought_at"]) * self.coins_bought[coin]["volume"] ) * (1 - (self.TRADING_FEE * 2)) self.session_profit_amount += profit print( f"Session profit: {self.session_profit_amount:.3f} in {datetime.now() - self.starting_time}" ) self.log( f"Sell: {self.coins_bought[coin]['volume']} {coin} - {self.coins_bought[coin]['bought_at']} " f"{self.prices[coin]['price'][-1]} Profit: {profit:.2f} {PriceChange - (self.TRADING_FEE * 2):.2f}%" ) self.remove_from_portfolio(coin) def buy(self, coin): volume = self.get_volume(coin) order = {} if not self.TEST_MODE: try: self.client.create_order( symbol=coin, side="BUY", type="MARKET", quantity=volume ) except Exception as e: print(e) else: order = self.client.get_all_orders(symbol=coin, limit=1) while not order: order = self.client.get_all_orders(symbol=coin, limit=1) sleep(0.5) else: order = { "symbol": coin, "orderId": 0, "time": datetime.now().timestamp(), "price": self.prices[coin]["price"][-1], "volume": volume, "stop_loss": self.STOP_LOSS, "take_profit": self.TAKE_PROFIT, } self.add_to_portfolio(order, volume) self.log(f"Buy: {volume} {coin} - {self.prices[coin]['price'][-1]}") def get_volume(self, coin): lot_size = {} info = self.client.get_symbol_info(coin) if info is None: sleep(1) return self.get_volume(coin) step_size = info["filters"][2]["stepSize"] lot_size[coin] = step_size.index("1") - 1 if lot_size[coin] < 0: lot_size[coin] = 0 volume = float(self.QUANTITY / float(self.prices[coin]["price"][-1])) if coin not in lot_size: volume = float("{:.1f}".format(volume)) else: if lot_size[coin] == 0: volume = int(volume) else: volume = float("{:.{}f}".format(volume, lot_size[coin])) return volume def sell_buy_check(self): coins_to_sell = [] for coin in self.coins_bought: TP = ( float(self.coins_bought[coin]["bought_at"]) + ( float(self.coins_bought[coin]["bought_at"]) * self.coins_bought[coin]["take_profit"] ) / 100 ) SL = ( float(self.coins_bought[coin]["bought_at"]) + ( float(self.coins_bought[coin]["bought_at"]) * self.coins_bought[coin]["stop_loss"] ) / 100 ) LastPrice = float(self.prices[coin]["price"][-1]) BuyPrice = float(self.coins_bought[coin]["bought_at"]) PriceChange = float((LastPrice - BuyPrice) / BuyPrice * 100) self.coins_bought[coin]["current_price"] = LastPrice self.coins_bought[coin]["current"] = PriceChange self.coins_bought[coin]["hold_dur"] = ( datetime.now().timestamp() - self.coins_bought[coin]["timestamp"] ) if LastPrice > TP: self.coins_bought[coin]["take_profit"] = PriceChange self.coins_bought[coin]["stop_loss"] = ( self.coins_bought[coin]["take_profit"] - 0.15 ) * 0.8 print( f"{coin} TP reached, adjusting TP {self.coins_bought[coin]['take_profit']:.2f} and SL " f"{self.coins_bought[coin]['stop_loss']:.2f}." ) elif self.prices[coin]["price"][-1] < SL: coins_to_sell.append(coin) with concurrent.futures.ThreadPoolExecutor() as executor: for coin in coins_to_sell: executor.submit(self.sell, coin) with concurrent.futures.ThreadPoolExecutor() as executor: for coin in self.prices: lp = self.prices[coin]["price"][0] # LAST PRICE pc = self.CHANGE_IN_PRICE # 3% mean = np.mean(self.prices[coin]["price"][1:]) last_price_plus_change = lp + (lp * pc) / 100 if last_price_plus_change < mean and coin not in self.coins_bought: executor.submit(self.buy, coin) else: pass def add_to_portfolio(self, order, volume): self.coins_bought[order["symbol"]] = { "symbol": order["symbol"], "order_id": order["orderId"], "timestamp": order["time"], "bought_at": order["price"], "current_price": order["price"], "hold_dur": 0, "volume": volume, "stop_loss": -self.STOP_LOSS, "take_profit": self.TAKE_PROFIT, "current": 0, } with open(self.coins_bought_file_path, "w") as file: json.dump(self.coins_bought, file, indent=4) def remove_from_portfolio(self, coin): self.coins_bought.pop(coin) with open(self.coins_bought_file_path, "w") as file: json.dump(self.coins_bought, file, indent=4) def update_portfolio(self): with open(self.coins_bought_file_path, "w") as file: json.dump(self.coins_bought, file, indent=4) if __name__ == "__main__": FreeMoney() ```
glepnir commented 2 years ago

I check the pyright server report. it only return a few symbols. so other functions symbols not show in winbar.

RAV64 commented 2 years ago

In your outline you do get all (or most) of the symbols though.

image

And I think my first post is still valid since the hierarchy you can see in the picture above isn't the same we get in this picture: (because there's freemoney>first_run and not freemoney>init>first_run) Also there is the get_prices() in outline and not in Do you use treesitter for outline and lsp for winbar?

glepnir commented 2 years ago

a wired problem. I will check it later.

glepnir commented 2 years ago

can you provide a min python code that can reproduce ?

RAV64 commented 2 years ago

Did some testing and came up with this

class FreeMoney:
    def __init__(self):
        self.first_run = True
        self.session_profit_percent = 0
glepnir commented 2 years ago

maybe add more function in this class would be nice .most like your post code.

RAV64 commented 2 years ago

Sorry I do not understand. Above 4 lines reproduce the bug already. There seems to be couple different problems with winbar :o

glepnir commented 2 years ago

because yesterday I use four lines example . I can confirm works on my local.but didn't work for you. so I think the exmaple code should be more

RAV64 commented 2 years ago

This doesn't work for me on the main branch or the version_2 branch. Can you confirm this works with your local setup?

class Class:
    def __init__(self):
        self.var1 = True
        self.var2 = False

Im missing the init from the winbar when hovering var1 and var2 but it can be seen when hovering init

glepnir commented 2 years ago

images

RAV64 commented 2 years ago

Your commit fixed that minimum test file but broke some other things :(

https://user-images.githubusercontent.com/73443709/185394685-91e74ac0-07c6-4f2d-9d43-b90eeaf99ca2.mov

glepnir commented 2 years ago

don't know why ..

RAV64 commented 2 years ago

Should you open this issue? Problem wasn't fixed yet.