kkharji / xbase

Develop Apple software products within your favorite editor.
MIT License
537 stars 17 forks source link

No autocomplete suggestion #218

Open ntdkhang opened 1 year ago

ntdkhang commented 1 year ago

When I start nvim in a .xcodeproject root, xbase starts running, create the buildServer and .compile file and outputs to log as expected, but there was no autocomplete, not even for basic swift commands. When I deleted xbase and run Sourcekit-lsp on its own, the lsp was working fine, showing suggestions for swift commands and functions in that file (but not methods/classes from other files).

Here's my xbase config

    use {
        'xbase-lab/xbase',
        run = 'make install', -- or "make install && make free_space" (not recommended, longer build time)
        config = function ()
            require'xbase'.setup({
                log_level = vim.log.levels.INFO,
                log_buffer = {
                    focus  = false,
                    default_direction = "horizontal",
                },
                sourcekit = {
                },
                simctl = {
                    iOS = {
                        "iPhone 14 Pro",
                    },
                },
                mappings = {
                    --- Whether xbase mapping should be disabled.
                    enable = true,
                    --- Open build picker. showing targets and configuration.
                    build_picker = 0, --- set to 0 to disable
                    --- Open run picker. showing targets, devices and configuration
                    run_picker = 0, --- set to 0 to disable
                    --- Open watch picker. showing run or build, targets, devices and configuration
                    watch_picker = 0, --- set to 0 to disable
                    --- A list of all the previous pickers
                    all_picker = "<leader>ef", --- set to 0 to disable
                },
            })
        end
    }

My lsp config for sourcekit

local lsp_config = require('lspconfig')
lsp_config.sourcekit.setup{
    root_dir = lsp_config.util.root_pattern("Package.swift", ".git", "*.xcodeproj")
}
lsp.setup()

When I run ~/.local/share/xbase/xbase it knows that I'm editing the file

2023-05-19T15:59:08.344477Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:133: Processed "ContentView.swift" [renamed]
2023-05-19T15:59:08.344504Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:115: Processing "ContentView.swift" [created]
2023-05-19T15:59:08.344603Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:133: Processed "ContentView.swift" [created]
2023-05-19T15:59:08.344623Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:115: Processing "ContentView.swift" [modified]
2023-05-19T15:59:08.344706Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:133: Processed "ContentView.swift" [modified]
2023-05-19T15:59:08.344726Z  INFO FSWatcher{name="WeatherClone"}: src/runtime/mod.rs:115: Processing "ContentView.swift~" [removed]

And here's the xbase-build-server.log

 INFO xbase_sourcekit_helper: Initialized
DEBUG xbase_sourcekit_helper: [ContentView.swift] Querying compile_db
 INFO xbase_sourcekit_helper: 
 INFO xbase_sourcekit_helper: Started
 INFO xbase_sourcekit_helper: Initialized
DEBUG xbase_sourcekit_helper: [ContentView.swift] Querying compile_db
 INFO xbase_sourcekit_helper: 
ERROR xbase_sourcekit_helper: Unhandled params: OptionsChangedRequest { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/dk/Documents/Dev/iOS/PersonalProjects/WeatherClone/WeatherClone/ContentView.swift", query: None, fragment: None }, action: Unregister }
DEBUG xbase_sourcekit_helper: [ContentView.swift] Using Cached file args
 INFO xbase_sourcekit_helper: 

Versions: macOS 12.5.1 Xcode Version 14.1 (14B47b)

kkharji commented 1 year ago

Hmmm I believe you haven't installed autocompletor? or which one are you using?

For xbase to take over and configure the setup. You need to have a configuration defined in xbase opts:

      sourcekit = {
        on_attach = function() end,
        handlers = function() end,
        capabilities = function() end,
      },
ntdkhang commented 1 year ago

I'm using lsp-zero.nvim which requires nvim-lspconfig and mason.nvim. I tried adding that sourcekit opt and it prints this error when opening the swift file: [lspconfig] unhandled error: vim/shared.lua:0: after the second argument: expected table, got function

kkharji commented 1 year ago

Oh, my bad, actually try this:

      sourcekit = {     },
ntdkhang commented 1 year ago

That's what I did initially and it didn't work

ntdkhang commented 1 year ago

How did you setup the sourcekit-lsp?

kkharji commented 1 year ago

Well I have custom setup. I use cmp for completion which has it's own complex setup. hmm I guess maybe you are missing https://github.com/hrsh7th/cmp-nvim-lsp

local dcapabilities = vim.lsp.protocol.make_client_capabilities()
local capabilities = vim.tbl_deep_extend("force", dcapabilities, {
  offsetEncoding = { "utf-16" }, -- fix issue with null-ls and c servers
  experimental = {
    hoverActions = true,
    hoverRange = true,
    serverStatusNotification = true,
    snippetTextEdit = true,
    codeActionGroup = true,
    ssr = true,
  },
  textDocument = {
    completion = {
      completionItem = {
        snippetSupport = true,
        preselectSupport = true,
        insertReplaceSupport = true,
        labelDetailsSupport = true,
        deprecatedSupport = false,
        commitCharactersSupport = true,
        tagSupport = { valueSet = { 1 } },
        resolveSupport = {
          properties = { "additionalTextEdits", "documentation", "detail" },
        },
      },
    },
  },
})
ntdkhang commented 1 year ago

cmp-nvim-lsp already comes with the lsp-zero setup that I have. The lsp works perfectly for other languages, it work for Swift too (without xbase installed). So I'm wondering if I might be doing anything wrong with my sourcekit-lsp setup that interfere with xbase.

ntdkhang commented 1 year ago

Here's what :LspInfo shows

 Client: sourcekit (id: 1, bufnr: [5])
    filetypes:       swift
    autostart:       true
    root directory:  /Users/dk/Documents/Dev/iOS/PersonalProject....
    cmd:             /usr/bin/sourcekit-lsp --log-level error

Then, :LspLog shows this:

[ERROR][2023-05-22 15:53:15] .../vim/lsp/rpc.lua:733    "rpc"   "/usr/bin/sourcekit-lsp"    "stderr"    "thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', crates/sourcekit-helper/src/main.rs:47:59\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"
kkharji commented 1 year ago

Nice that's a clear lead. I will look into it in few hours. Thanks

rsdenijs commented 1 year ago

For what it is worth I'm seeing the same problem

 "rpc"   "sourcekit-lsp" "stderr"    "thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', "
 "rpc"   "sourcekit-lsp" "stderr"    "crates/sourcekit-helper/src/main.rs"
 "rpc"   "sourcekit-lsp" "stderr"    ":47:59\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"
kkharji commented 1 year ago

@rsdenijs can you give more information on your project?

rsdenijs commented 1 year ago

Yes, I am a regular neovim user and was playing around with xcode/swiftUI intro tutorials. I was trying to get some level of LSP working in neovim.

kkharji commented 1 year ago

Yes, I am a regular neovim user and was playing around with xcode/swiftUI intro tutorials. I was trying to get some level of LSP working in neovim.

Oh nice. You ain't using any type of xcodeproj generator just directly from xcode created.

rsdenijs commented 1 year ago

Correct. Just created the project in Xcode and trying to do some basic development on it in neovim.

bengidev commented 10 months ago

@kkharji Can you give your setup repos for example purpose, mate?

I think my setup was failed and need some reference to make the plugin works.