SolaWing / xcode-build-server

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

Description of the process #51

Closed wojciech-kulik closed 8 months ago

wojciech-kulik commented 8 months ago

Hi!

I'm very curious how it all works. In issues, I constantly see the keyword flags, but I don't understand what they are for and how they are used or produced (besides that they come from build logs).

It would be really nice if you could provide in README or in another document a short description of the process. I guess it could help others to contribute and better understand the tool and its limitations.

SolaWing commented 8 months ago

Oh, the flags’s full name is compile flags, it’s coming from clang and I keep call it the same way. see https://clangd.llvm.org/config#compileflags

it’s actually the same things as args pass to clang or swiftc, to make the compile works.

eg: -F flag to tell how to find the frameworks. for which flag is used for, you can call -help on clang or swiftc

xcode-build-server actually get the compile command from logs, and feed it to lsp, with some compatibility issue handled(eg: lsp doesn’t recognize flags read from file by @file, xcode-build-server expand it).

flags is the main info lsp need to know and it normally same as compile command. with it, sourcekit can do diagnostics and completions. these flags can dynamic changes by notify lsp.

index store path is another info sourcekit need to know, it store all symbol’s info and lsp rely on it to do jump to definition and jump to reference. it normally updated by compile command and shared the some path in a workspace. change build root will change this path. unfortunately this path is give to lsp as init response and can’t dynamic changes.

xcode-build-server’s responsibility is get these info and pass it to lsp, to make lsp works.

wojciech-kulik commented 8 months ago

Thank you for the great explanation!

I'm checking build logs and I see something like:

{
  "kind": "began",
  "name": "compile",
  "command": "\/Applications\/Xcode.app\/Contents\/Developer\/Toolchains\/XcodeDefault.xctoolchain\/usr\/bin\/swift-frontend -emit-module ....",
  "command_executable": "\/Applications\/Xcode.app\/Contents\/Developer\/Toolchains\/XcodeDefault.xctoolchain\/usr\/bin\/swift-frontend",
  "command_arguments": [
    "-emit-module",
    "-experimental-skip-non-inlinable-function-bodies-without-types",
    ...

Do you get flags form here?

SolaWing commented 8 months ago

similar somethings. but use swiftc command, not swift-frontend