1{ stdenv, lib, fetchFromGitHub, cmake, ninja, python
2, withGocode ? true, gocode
3, withGodef ? true, godef
4, withGotools? true, gotools
5, withTypescript ? true, typescript
6, abseil-cpp, boost, llvmPackages
7, fixDarwinDylibNames, Cocoa
8}:
9
10stdenv.mkDerivation {
11 pname = "ycmd";
12 version = "unstable-2022-08-15";
13 disabled = !python.isPy3k;
14
15 # required for third_party directory creation
16 src = fetchFromGitHub {
17 owner = "ycm-core";
18 repo = "ycmd";
19 rev = "323d4b60f077bd07945f25a60c4584843ca851fb";
20 sha256 = "sha256-5IpXMQc3QIkKJkUrOPSRzciLvL1nhQw6wlP+pVnIucE=";
21 fetchSubmodules = true;
22 };
23
24 nativeBuildInputs = [ cmake ninja ]
25 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
26 buildInputs = with python.pkgs; with llvmPackages; [ abseil-cpp boost libllvm.all libclang.all ]
27 ++ [ jedi jedi-language-server pybind11 ]
28 ++ lib.optional stdenv.isDarwin Cocoa;
29
30 buildPhase = ''
31 export EXTRA_CMAKE_ARGS="-DPATH_TO_LLVM_ROOT=${llvmPackages.libllvm} -DUSE_SYSTEM_ABSEIL=true"
32 ${python.pythonOnBuildForHost.interpreter} build.py --system-libclang --clang-completer --ninja
33 '';
34
35 dontConfigure = true;
36
37 # remove the tests
38 #
39 # make __main__.py executable and add shebang
40 #
41 # copy over third-party libs
42 # note: if we switch to using our packaged libs, we'll need to symlink them
43 # into the same spots, as YouCompleteMe (the vim plugin) expects those paths
44 # to be available
45 #
46 # symlink completion backends where ycmd expects them
47 installPhase = ''
48 rm -rf ycmd/tests
49
50 chmod +x ycmd/__main__.py
51 sed -i "1i #!${python.interpreter}\
52 " ycmd/__main__.py
53
54 mkdir -p $out/lib/ycmd
55 cp -r ycmd/ CORE_VERSION *.so* *.dylib* $out/lib/ycmd/
56
57 mkdir -p $out/bin
58 ln -s $out/lib/ycmd/ycmd/__main__.py $out/bin/ycmd
59
60 # Copy everything: the structure of third_party has been known to change.
61 # When linking our own libraries below, do so with '-f'
62 # to clobber anything we may have copied here.
63 mkdir -p $out/lib/ycmd/third_party
64 cp -r third_party/* $out/lib/ycmd/third_party/
65
66 '' + lib.optionalString withGocode ''
67 TARGET=$out/lib/ycmd/third_party/gocode
68 mkdir -p $TARGET
69 ln -sf ${gocode}/bin/gocode $TARGET
70 '' + lib.optionalString withGodef ''
71 TARGET=$out/lib/ycmd/third_party/godef
72 mkdir -p $TARGET
73 ln -sf ${godef}/bin/godef $TARGET
74 '' + lib.optionalString withGotools ''
75 TARGET=$out/lib/ycmd/third_party/go/src/golang.org/x/tools/cmd/gopls
76 mkdir -p $TARGET
77 ln -sf ${gotools}/bin/gopls $TARGET
78 '' + lib.optionalString withTypescript ''
79 TARGET=$out/lib/ycmd/third_party/tsserver
80 ln -sf ${typescript} $TARGET
81 '';
82
83 # fixup the argv[0] and replace __file__ with the corresponding path so
84 # python won't be thrown off by argv[0]
85 postFixup = ''
86 substituteInPlace $out/lib/ycmd/ycmd/__main__.py \
87 --replace __file__ "'$out/lib/ycmd/ycmd/__main__.py'"
88 '';
89
90 meta = with lib; {
91 description = "A code-completion and comprehension server";
92 homepage = "https://github.com/ycm-core/ycmd";
93 license = licenses.gpl3;
94 maintainers = with maintainers; [ rasendubi lnl7 siriobalmelli ];
95 platforms = platforms.all;
96 };
97}