SolaWing / xcode-build-server

a build server protocol implementation for integrate xcode with sourcekit-lsp
MIT License
283 stars 16 forks source link

LSP doesn't come with code completions/suggestions #32

Closed bengidev closed 3 months ago

bengidev commented 3 months ago

Hello, i haven't code completions/suggestions while my LSP is successfully activate and i've generate buildServer.json in the root of my working directories. Here are some screenshoots for my problem:

So, that's my report for you. I hope i can develop iOS app outside XCode environment. Thank you very much for your great work, mate 🍻

SolaWing commented 3 months ago

@bengidev Your build_root_dir seems incorrect.. xcode-build-server expect to read xcode build log from <build_root_dir>/Logs/Build/ dir. this dir normally default to ~/Library/Developer/Xcode/DerivedData/XXX-hash

can you show me your xcodebuild -showBuildSettings -scheme Orbinews -workspace XXX | fgrep BUILD_DIR result?

SolaWing commented 3 months ago

seems you change the default build dir, and the build_dir has space in path, so extract build_root failed..

SolaWing commented 3 months ago

I push a fix to allow space in BUILD_DIR, you can check if your LSP works?

wojciech-kulik commented 3 months ago

@bengidev did it help?

bengidev commented 3 months ago

I've try this way, don't hesitate to correct me.

I'm sorry for my late responses, mate 🍻

SolaWing commented 3 months ago

@bengidev this time your build_root seems correct.

I see you use -project(not workspace) as config, and your xcode is custom Xcode-15.2.app, so you should check you use same project and same xcode version as xcode-build-server config. after you build, you should see a newer log in your configed build root, see ls -al ~/Library/Developer/Xcode/DerivedData/Tester-*/Logs/Build, xcode-build-server get flags from it.

if you log generate correctly, you can check detail logs by export envirment: SOURCEKIT_LOGGING=3, you export in your terminal if you use terminal vim, or set in your vim's environment before lsp start.

you can also check if you create a newer demo project, if it works?

bengidev commented 3 months ago

I'm sorry, i don't get what you suggestso you should check you use same project and same xcode version as xcode-build-server config. Can you explain more simpler to me?

And where am i supposed to put this SOURCEKIT_LOGGING=3?

SolaWing commented 3 months ago
  1. Run xcode build, and check a newer log file generated in the build_root dir ls -al ~/Library/Developer/Xcode/DerivedData/Tester-*/Logs/Build
  2. In vim before lsp setup, call vimscript let $SOURCEKIT_LOGGING="3"
bengidev commented 3 months ago

I try to run your number 1 suggestions, but i still don't understand your number 2 suggestions, sorry.

I try to create new project with name NewTest:

SolaWing commented 3 months ago

seems you have multiple NewTest log output, and newest is build at 14:53. is this the NewTest-fdomdvhi* dir same as build_root? did this new project works?

for set environment, you can exe script at begin of your nviminit, use: vim.env.SOURCEKIT_LOGGING="3" in lua, or let $SOURCEKIT_LOGGING="3" in vimscript

bengidev commented 3 months ago
SolaWing commented 3 months ago

Can you upload the LspLog as file? screenshot seems be truncated

bengidev commented 3 months ago

This is the LspLog.txt: LspLog.txt

SolaWing commented 3 months ago

from the log seems xcode-builld-server cannot read correct flags, and return the default flags: ["/Users/beng/Downloads/NewTest/NewTest/NewTest/ViewController.swift", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"], which is not compatible with your Xcode-15.2.0.app version.

when you run build, you can check if your build updating logs in ls -al /Users/beng/Library/Developer/Xcode/DerivedData/NewTest-domdvhivimfpzmckkmtgkilvyjxk/Logs/Build dir. you also can view your build log output, see if it has same base dir as /Users/beng/Library/Developer/Xcode/DerivedData/NewTest-domdvhivimfpzmckkmtgkilvyjxk/

(by the way, if you has the full xcode log, you can copy it and run pbpaste | xcode-build-server parse at you lsp root dir, as Readme Manual Parse Xcodebuild log shows, though this way will not auto update new flags when you build)

if the build dir correct and the log is updated, you can check the log-file contains the correct logs (extract it by cmd xcode-build-server debug print-xclog <path_to.xcactivitylog>, I just provide it in newest version) the log should contains a cmd like /Applications/Xcode-15.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -module-name <YourModule>. if this case, you completion should work. or if log correct, but xcode-build-server can't analyze the log(by cmd xcode-build-server parse -l <Path-to.xcactivitylog> -o -), you can upload the log file for me to debug it.

bengidev commented 3 months ago
SolaWing commented 3 months ago

your build failed without any module flags output?

For your lsp to works, you need to:

  1. Run Build, and see the build log. for simple you should try compile in xcode first, this avoid complex build params for xcodebuild and can show all logs, if this way works, we can further check the xcodebuild integration issue.
  2. The Xcode build should success, and the build product root should in /Users/beng/Library/Developer/Xcode/DerivedData/NewTest-domdvhivimfpzmckkmtgkilvyjxk/
  3. check in ls -al /Users/beng/Library/Developer/Xcode/DerivedData/NewTest-domdvhivimfpzmckkmtgkilvyjxk/Logs/Build, LogStoreManifest.plist and a newer xcactivitylog is updated.
  4. as there is log in Logs/Build, the lsp should works. if not, upload this log dir for me to debug.
  5. for manually parse flags, you can goto your xcode build log page, export all log to file(eg /tmp/BuildXXX.log), and then run cmd xcode-build-server parse </tmp/BuildXXX.log>. this should also works.
bengidev commented 3 months ago

I don't know if this works as we expected, but i've try to create new iOS App called Space News, and i've build and run previously in XCode, and when i generate buildServer.json, and then i try to run in NeoVim again, it seems to works. Like i try to type import fo and then code completions/suggestions shows up with Foundation and known as Module, not Text again. You can see my screenshoots down below:

You also can check my Logs directories here

wojciech-kulik commented 3 months ago

Maybe try also creating first a project that doesn't contain white spaces in path to make sure that it is not causing any additional problems. And try building the project for tests from Xcode first.

SolaWing commented 3 months ago

Finally you compile via xcode and it works successfully. for XCTest file to work, you need to build or run test, with the same scheme to generate index and flags.

if you use same scheme to run app and test, like scheme page shows, you just need to run test by Product->Test(hotkey: <Cmd-U>):

图片

if you test target is in a different schema, you should ensure you config xcode-build-server with same schema and then build test.

for vim plugin works and how to bind vim build to xcode-build-server, you can ask @wojciech-kulik for advice

bengidev commented 3 months ago

I try available suggestions, and this is what i get.

And i think finally it works really perfect. Should i close the issue?

SolaWing commented 3 months ago

Congratulations! If you has no more questions, feel free to close the issue

bengidev commented 3 months ago

I think this works very perfect, and i've try to maximize the potentials to see great articles from @wojciech-kulik again.

Thank you very much, for all of you. Keep your great works, and enjoy your life, mate 🍻

ghashy commented 3 months ago

I have been experimenting with the Xcode-Build-Server project using Helix editor and have noticed an interesting behavior regarding LSP suggestions. When creating Xcode projects (Xcode 15.2 (15C500b), Ventura 13.6.1) with the 'create git repo on my mac' option selected, LSP suggestions work perfectly. However, if I disable this option and create the project without a git repository, LSP suggestions do not work. I have verified that all paths are correct and have tested with other projects, but the behavior persists. Interestingly, if I create a project with git disabled and then create a repo with git init, LSP suggestions start working.

I thought this information might be helpful to others who are using the Xcode-Build-Server project and experiencing similar issues.

SolaWing commented 3 months ago

@ghashy seems this relative how your editor recognize lsp root. git dir normally recognized as lsp root. you should confirm the build server dir is your lsp root dir. this should confirm by lsp logs

wojciech-kulik commented 3 months ago

@ghashy it's a matter of setting a proper search for your LSP. Here is what I'm doing in my nvim-lspconfig config:

    lspconfig["sourcekit"].setup({
      capabilities = capabilities,
      on_attach = on_attach,
      cmd = {
        vim.trim(vim.fn.system("xcrun -f sourcekit-lsp")),
      },
      root_dir = function(filename, _)
        local util = require("lspconfig.util")
        return util.root_pattern("buildServer.json")(filename)
          or util.root_pattern("*.xcodeproj", "*.xcworkspace")(filename)
          or util.find_git_ancestor(filename)
          or util.root_pattern("Package.swift")(filename)
      end,
    })

If you run :LspInfo you can check if the root is properly set.