├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── lib ├── __init__.py ├── server.py ├── services │ ├── __init__.py │ ├── clang_format │ │ ├── __init__.py │ │ └── clang_format.py │ ├── clang_tidy │ │ ├── __init__.py │ │ └── clang_tidy.py │ ├── code_completion │ │ ├── __init__.py │ │ └── code_completion.py │ ├── disassembly │ │ └── disassembly.py │ ├── project_builder │ │ ├── __init__.py │ │ └── project_builder.py │ └── source_code_model │ │ ├── __init__.py │ │ ├── diagnostics │ │ ├── __init__.py │ │ └── diagnostics.py │ │ ├── go_to_definition │ │ ├── __init__.py │ │ └── go_to_definition.py │ │ ├── go_to_include │ │ ├── __init__.py │ │ └── go_to_include.py │ │ ├── indexer │ │ ├── __init__.py │ │ └── indexer.py │ │ ├── semantic_syntax_highlight │ │ ├── __init__.py │ │ └── semantic_syntax_highlight.py │ │ ├── source_code_model.py │ │ └── type_deduction │ │ ├── __init__.py │ │ └── type_deduction.py └── utils.py ├── make_color.py ├── plugin ├── cxxd.vim └── cxxd │ ├── server.vim │ ├── services │ ├── clang_format.vim │ ├── clang_tidy.vim │ ├── code_completion.vim │ ├── disassembly.vim │ ├── project_builder.vim │ ├── source_code_model.vim │ └── source_code_model │ │ ├── diagnostics.vim │ │ ├── go_to_definition.vim │ │ ├── go_to_include.vim │ │ ├── indexer.vim │ │ ├── semantic_syntax_highlight.vim │ │ └── type_deduction.vim │ └── utils.vim └── syntax └── cpp └── cxxd.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cxxd/cxxd"] 2 | path = lib/cxxd 3 | url = https://github.com/JBakamovic/cxxd.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Contents 2 | * [Introduction](#introduction) 3 | * [Installation](#installation) 4 | * [Dependencies](#dependencies) 5 | * [Plugin managers](#plugin-managers) 6 | * [Manual](#manual) 7 | * [Features](#features) 8 | * [Supported platforms](#supported-platforms) 9 | * [Getting started](#getting-started) 10 | * [Colorschemes](#colorschemes) 11 | * [Usage](#usage) 12 | * [Screenshots](#screenshots) 13 | * [FAQ](#faq) 14 | 15 | # Introduction 16 | 17 | This is a Vim frontend for [cxxd](https://github.com/JBakamovic/cxxd) server. 18 | 19 | # Installation 20 | 21 | Any of your preferred way of installing Vim plugins should be fine. Please note the necessity for recursive clone. For example: 22 | 23 | ## Dependencies 24 | [Here](https://github.com/JBakamovic/cxxd#dependencies). 25 | 26 | ## Plugin managers 27 | 28 | ### Pathogen 29 | * `$ git clone --recursive https://github.com/JBakamovic/cxxd-vim.git ~/.vim/bundle/cxxd-vim` 30 | * `$ git clone https://github.com/JBakamovic/yaflandia.git ~/.vim/bundle/yaflandia` (accompanying colorscheme) 31 | * `$ git clone https://github.com/Shirk/vim-gas.git ~/.vim/bundle/vim-gas` (optional but for better experience with disassembling) 32 | 33 | ### Vundle 34 | After cloning the repository with: 35 | * `$ git clone --recursive https://github.com/JBakamovic/cxxd-vim.git` 36 | * `$ git clone https://github.com/JBakamovic/yaflandia.git` (accompanying colorscheme) 37 | * `$ git clone https://github.com/Shirk/vim-gas.git` 38 | 39 | Add the following to your `.vimrc` 40 | * `Plugin 'JBakamovic/cxxd-vim'` 41 | * `Plugin 'JBakamovic/yaflandia'` (accompanying colorscheme) 42 | * `Plugin 'Shirk/vim-gas'` (optional but for better experience with disassembling) 43 | 44 | ## Manual 45 | 46 | If you're not using any of the plugin managers, you can simply clone the repository into your `~/.vim/` directory: 47 | * `$ git clone --recursive https://github.com/JBakamovic/cxxd-vim.git ~/.vim/cxxd-vim` 48 | * `$ git clone https://github.com/JBakamovic/yaflandia.git ~/.vim/yaflandia` (accompanying colorscheme) 49 | * `$ git clone https://github.com/Shirk/vim-gas.git ~/.vim/vim-gas` (optional but for better experience with disassembling) 50 | 51 | # Features 52 | 53 | [Here](https://github.com/JBakamovic/cxxd/blob/master/README.md#features) 54 | 55 | # Supported platforms 56 | 57 | [Here](https://github.com/JBakamovic/cxxd/blob/master/README.md#supported-platforms) 58 | 59 | # Getting started 60 | 61 | You need to provide [`.cxxd_config.json`](https://github.com/JBakamovic/cxxd#configuration) file at the root of your source code repository. You will also need to generate a [compilation database](https://github.com/JBakamovic/cxxd#compilation-database). 62 | 63 | You can use [`.cxxd_config.json` example configuration](https://github.com/JBakamovic/cxxd#example-of-configuration) and tweak it to your needs. 64 | 65 | # Colorschemes 66 | 67 | Compared to the vanilla `Vim` syntax highlighting mechanism, `cxxd` brings _semantic_ syntax highlighting which not only that it attributes to the visual appeal but it also provides an immediate feedback on the correctness of your code (by not coloring the code in case of errors). In order to take advantage of that feature one has to use a colorscheme that knows how to make use of [additional higlighting groups](syntax/cpp/cxxd.vim). 68 | 69 | Vanilla `Vim` colorschemes do not handle these groups by default so one will have to either tweak those existing colorschemes to include those groups or simply use [`yaflandia`](https://github.com/JBakamovic/yaflandia) for the start. 70 | 71 | If you want to to tweak your favorite colorscheme, you can try using the [`make_color.py `](make_color.py) utility so that it becomes compatible. It only links existing highlighting groups to the ones generated by cxxd so it shouldn't be destructive by any means. 72 | 73 | # Usage 74 | Command | Default Key-Mapping | Purpose 75 | ------- | :-------------------: | -------- 76 | `CxxdStart ` | None | Starts `cxxd` server for given project directory in auto-discovery mode. Builds symbol index database. Most other commands will not have effect until symbol index database is built (which may take some time depending on the project size). 77 | `CxxdStart ` | None | Starts `cxxd` server for given project directory and given build-target. Build-target must exist in `.cxxd_config.json` file. Builds symbol index database. Most other commands will not have effect until symbol index database is built (which may take some time depending on the project size). 78 | `CxxdStop` | None | Stops `cxxd` server. 79 | `CxxdRebuildIndex` | `r` | Rebuilds the symbol index database. 80 | `CxxdGoToInclude` | `` and `` | Jumps to the file included via `#include` directive. 81 | `CxxdGoToIncludeInPreview` | `` | Peeks into the file included via `#include` directive and shows it in a small preview window. 82 | `CxxdGoToDefintion` | `` and `` | Jumps to the symbol definition under the cursor. 83 | `CxxdGoToDefintionInPreview` | `` | Peeks into the definition and shows it in a small preview window. 84 | `CxxdFindAllReferences` | `s` | Finds all references of symbol under the cursor. Results are stored into a `QuickFix` list once the operation is completed. 85 | `CxxdFetchAllDiagnostics` | `d` | Fetches all diagnostics of all source files indexed. Results are stored into a `QuickFix` list once the operation is completed. 86 | `CxxdAnalyzerClangTidyBuf` | `` | Runs `clang-tidy` on current file. Results are stored into a `QuickFix` list once `clang-tidy` is completed. 87 | `CxxdAnalyzerClangTidyApplyFixesBuf` | `` | Runs `clang-tidy` on current file and applies the fixes. Results are stored into a `QuickFix` list once `clang-tidy` is completed. 88 | `CxxdBuildRun` | `` | Runs a build with `` which is provided in `.cxxd_config.json`. Build command that will be run will correspond to the way how `CxxdServer` was started, e.g. ``. 89 | `CxxdBuildRunWithParams ` | None | Manual way of doing the `CxxdBuildRun`. Runs a build with `` provided. `` can be of any arbitrary form which fits the build system your project is using (e.g. `make`, `make clean`, `make debug`, `make test`, etc.). Results are stored into a `QuickFix` list once the `` is completed. 90 | `CxxdDisassemblyPickTarget` | None | Opens a list of available targets (executables) and allows you to select one of the them you're interested in into disassemblying. This target will be used when `CxxdDisassemblyPickSymbol` will be run. 91 | `CxxdDisassemblyPickSymbol` | None | Position a cursor at some symbol of interest, e.g. some function, and run this command. It will open a list of potential symbols (this list will ideally be of size 1). After confirming your choice from the list, a disassembled binary will be opened and cursor will be positioned at the symbol which you just selected. 92 | `lopen` | None | Opens location list containing `clang-fix-it` hints for current buffer. 93 | `w` | None | Re-formats the source code in current buffer with `clang-format`. 94 | `mouse hover over the symbol` | None | If hovered over the C or C++ sourc-code, it will show a symbol type in a tooltip. If hovered over the assembly (e.g. in disassembled binary after `CxxdDisassemblyPickSymbol`), it will show the documentation of the underlying ASM instruction in a tooltip. 95 | `colorscheme yaflandia` | None | Activates a colorscheme which has support for semantic syntax highlighting. Any other compatible colorscheme can be used of course. 96 | 97 | # Screenshots 98 | ## Semantic syntax highlighting 99 | 100 | ![Semantic syntax hl](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/semantic-syntax-hl.png) 101 | 102 | ## Go-to-definition 103 | 104 | ![Go to definition](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/go-to-definition.gif) 105 | 106 | ## Go-to-include 107 | 108 | ![Go to include](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/go-to-include.gif) 109 | 110 | ## Find-all-references 111 | 112 | ![Find all references](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/find-all-references.gif) 113 | 114 | ## Fetch-all-diagnostics 115 | 116 | TBD 117 | 118 | ## Type-deduction 119 | 120 | ![Type deduction](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/type-deduction.gif) 121 | 122 | ## Clang-fix-it hints 123 | 124 | ![Clang-fix-it hints](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/hints-fixits.gif) 125 | 126 | ## Clang-format 127 | 128 | ![Clang-format](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/clang-format.gif) 129 | 130 | ## Clang-tidy 131 | 132 | ![Clang-tidy](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/clang-tidy.gif) 133 | 134 | ## Project build 135 | 136 | ![Project build](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/project-build.gif) 137 | 138 | ## Disassembly 139 | 140 | Use https://github.com/Shirk/vim-gas.git for better ASM syntax highlighting experience. See [Dependencies](#dependencies) section for more details. 141 | 142 | ![Disassembly](https://raw.githubusercontent.com/wiki/JBakamovic/cxxd-vim/images/disassembly.gif) 143 | 144 | # FAQ 145 | 146 | ## I can't seem to see the effect of semantic syntax highlighting? 147 | 148 | Make sure you're using a compatible colorscheme. You can either use (e.g. [yaflandia](https://github.com/JBakamovic/yaflandia)) or use [`make_color.py`](make_color.py) utility to convert the colorscheme you're using. 149 | 150 | ## Not getting the behavior you expected? 151 | 152 | Due to incorrect configuration, or lack of it, source code indexer might have stumbled upon the problems. Please use `CxxdFetchAllDiagnostics` command to debug the issues. 153 | -------------------------------------------------------------------------------- /lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/__init__.py -------------------------------------------------------------------------------- /lib/server.py: -------------------------------------------------------------------------------- 1 | import cxxd.server 2 | import services.clang_format.clang_format 3 | import services.clang_tidy.clang_tidy 4 | import services.project_builder.project_builder 5 | import services.source_code_model.source_code_model 6 | import services.code_completion.code_completion 7 | import services.disassembly.disassembly 8 | 9 | def get_instance(handle, project_root_directory, target_configuration, args): 10 | vim_instance = args 11 | return cxxd.server.Server( 12 | handle, 13 | project_root_directory, 14 | target_configuration, 15 | services.source_code_model.source_code_model.VimSourceCodeModel(vim_instance), 16 | services.project_builder.project_builder.VimProjectBuilder(vim_instance), 17 | services.clang_format.clang_format.VimClangFormat(vim_instance), 18 | services.clang_tidy.clang_tidy.VimClangTidy(vim_instance), 19 | services.code_completion.code_completion.VimCodeCompletion(vim_instance), 20 | services.disassembly.disassembly.VimDisassembly(vim_instance) 21 | ) 22 | -------------------------------------------------------------------------------- /lib/services/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/__init__.py -------------------------------------------------------------------------------- /lib/services/clang_format/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/clang_format/__init__.py -------------------------------------------------------------------------------- /lib/services/clang_format/clang_format.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | from cxxd.service_plugin import ServicePlugin 4 | 5 | class VimClangFormat(ServicePlugin): 6 | def __init__(self, servername): 7 | self.servername = servername 8 | 9 | def startup_callback(self, success, payload, startup_payload): 10 | Utils.call_vim_remote_function(self.servername, "cxxd#services#clang_format#start_callback(" + str(int(success)) + ")") 11 | 12 | def shutdown_callback(self, success, payload, shutdown_payload): 13 | reply_with_callback = bool(payload[0]) 14 | if reply_with_callback: 15 | Utils.call_vim_remote_function(self.servername, "cxxd#services#clang_format#stop_callback(" + str(int(success)) + ")") 16 | 17 | def __call__(self, success, payload, args): 18 | if not success: 19 | logging.error("Something went wrong with clang-format ... success={0}, payload={1}, args={2}.".format(success, payload, args)) 20 | Utils.call_vim_remote_function(self.servername, "cxxd#services#clang_format#run_callback(" + str(int(success)) + ", '" + payload[0] + "')") 21 | -------------------------------------------------------------------------------- /lib/services/clang_tidy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/clang_tidy/__init__.py -------------------------------------------------------------------------------- /lib/services/clang_tidy/clang_tidy.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | from cxxd.service_plugin import ServicePlugin 4 | 5 | class VimClangTidy(ServicePlugin): 6 | def __init__(self, servername): 7 | self.servername = servername 8 | 9 | def startup_callback(self, success, payload, startup_payload): 10 | Utils.call_vim_remote_function(self.servername, "cxxd#services#clang_tidy#start_callback(" + str(int(success)) + ")") 11 | 12 | def shutdown_callback(self, success, payload, shutdown_payload): 13 | reply_with_callback = bool(payload[0]) 14 | if reply_with_callback: 15 | Utils.call_vim_remote_function(self.servername, "cxxd#services#clang_tidy#stop_callback(" + str(int(success)) + ")") 16 | 17 | def __call__(self, success, payload, clang_tidy_output): 18 | def call_vim_rpc(status, filename, fixes_applied, clang_tidy_output): 19 | Utils.call_vim_remote_function( 20 | self.servername, 21 | "cxxd#services#clang_tidy#run_callback(" + str(int(status)) + ", '" + filename + "', " + str(int(fixes_applied)) + ", '" + clang_tidy_output + "')" 22 | ) 23 | 24 | if success: 25 | call_vim_rpc(success, payload[0], payload[1], clang_tidy_output) 26 | else: 27 | call_vim_rpc(success, payload[0], payload[1], '') 28 | logging.error("Something went wrong with clang-tidy ... success={0}, payload={1}, args={2}.".format(success, payload, clang_tidy_output)) 29 | -------------------------------------------------------------------------------- /lib/services/code_completion/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/code_completion/__init__.py -------------------------------------------------------------------------------- /lib/services/code_completion/code_completion.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import tempfile 4 | from utils import Utils 5 | from cxxd.parser.ast_node_identifier import ASTNodeId 6 | from cxxd.parser.clang_parser import ClangParser 7 | from cxxd.service_plugin import ServicePlugin 8 | from cxxd.services.code_completion.code_completion import CodeCompletionRequestId 9 | 10 | class VimCodeCompletion(ServicePlugin): 11 | def __init__(self, servername): 12 | self.servername = servername 13 | self.code_complete_candidates_output = os.path.join(tempfile.gettempdir(), self.servername + 'code_complete_candidates') 14 | 15 | def _create_vim_complete_item(self, candidate, detailed_candidate, kind, result_type, extra_documentation = None): 16 | return { 17 | 'word' : candidate, # On item selection, insert shortened form of the candidate (e.g. function without parameters) 18 | 'abbr' : detailed_candidate, # But still show detailed information about the candidate when available (e.g. function arguments) 19 | 'kind' : kind, 20 | 'menu' : result_type if result_type else '', 21 | 'info' : extra_documentation if extra_documentation else '', 22 | 'dup' : 1, # Function overloads, e.g. push_back(const value_type&&) and push_back(value_type&&), 23 | # will result in 'word' duplicates (e.g. multiple push_back's). 24 | # As duplicate 'word's will not be added by default, we must set this 25 | # property in order to preserve all of the overloads in the list. 26 | } 27 | 28 | def _extract_chunks(self, completion_string): 29 | # TODO handle isKindOptional, isKindInformative and others which make sense 30 | result_type, candidate, params = None, None, [] 31 | for chunk in completion_string: 32 | if chunk.isKindTypedText(): 33 | candidate = chunk.spelling 34 | elif chunk.isKindResultType(): 35 | result_type = chunk.spelling 36 | elif chunk.isKindPlaceHolder(): 37 | params.append(chunk.spelling) 38 | return result_type, candidate, params 39 | 40 | def _ast_node_id_to_vim_complete_item_kind(self, ast_node_id): 41 | # Vim does not have support for all of the kinds we are able to identify with clang, so we do 42 | # our best to map those remaining in the best category. 43 | 44 | # 'n' namespace (NOTE: not really supported according to :help complete-items but shows up nicely in pum) 45 | if ast_node_id in [\ 46 | ASTNodeId.getNamespaceId(), 47 | ASTNodeId.getNamespaceAliasId()]: 48 | return 'n' 49 | 50 | # 'v' variable 51 | if ast_node_id in [\ 52 | ASTNodeId.getLocalVariableId(), 53 | ASTNodeId.getFunctionParameterId(), 54 | ASTNodeId.getTemplateTypeParameterId(), 55 | ASTNodeId.getTemplateNonTypeParameterId(), 56 | ASTNodeId.getTemplateTemplateParameterId()]: 57 | return 'v' 58 | 59 | # 'f' function or method 60 | if ast_node_id in [\ 61 | ASTNodeId.getFunctionId(), 62 | ASTNodeId.getMethodId()]: 63 | return 'f' 64 | 65 | # 'm' member of a struct or class 66 | if ast_node_id in [\ 67 | ASTNodeId.getClassId(), 68 | ASTNodeId.getStructId(), 69 | ASTNodeId.getEnumId(), 70 | ASTNodeId.getEnumValueId(), 71 | ASTNodeId.getUnionId(), 72 | ASTNodeId.getFieldId()]: 73 | return 'm' 74 | 75 | # 't' typedef 76 | if ast_node_id in [\ 77 | ASTNodeId.getTypedefId()]: 78 | return 't' 79 | 80 | # 'd' #define or macro 81 | if ast_node_id in [\ 82 | ASTNodeId.getMacroInstantiationId(), 83 | ASTNodeId.getMacroDefinitionId()]: 84 | return 'd' 85 | 86 | # Otherwise we return an empty Vim kind 87 | logging.error("Unable to map AST node id '{0}' to available Vim kinds!".format(ast_node_id)) 88 | return '' 89 | 90 | def startup_callback(self, success, payload, startup_payload): 91 | Utils.call_vim_remote_function(self.servername, "cxxd#services#code_completion#start_callback(" + str(int(success)) + ")") 92 | 93 | def shutdown_callback(self, success, payload, shutdown_payload): 94 | reply_with_callback = bool(payload[0]) 95 | if reply_with_callback: 96 | Utils.call_vim_remote_function(self.servername, "cxxd#services#code_completion#stop_callback(" + str(int(success)) + ")") 97 | 98 | def __call__(self, success, payload, code_completion_results): 99 | if not success: 100 | logging.error('Something went wrong in code-completion service ... Payload = {0}'.format(payload)) 101 | 102 | code_completion_op_id = int(payload[0]) 103 | if code_completion_op_id == CodeCompletionRequestId.CODE_COMPLETE: 104 | self.__code_complete(success, payload, code_completion_results) 105 | elif code_completion_op_id == CodeCompletionRequestId.CACHE_WARMUP: 106 | self.__cache_warmup(success, payload, code_completion_results) 107 | else: 108 | logging.error('Invalid code-completion request ID: {0}'.format(code_completion_op_id)) 109 | 110 | def __cache_warmup(self, success, payload, code_completion_results): 111 | logging.info('Warming up the code-completion cache done') 112 | 113 | def __code_complete(self, success, payload, code_completion_results): 114 | def call_vim_rpc(status, completion_candidates, length): 115 | Utils.call_vim_remote_function( 116 | self.servername, 117 | "cxxd#services#code_completion#run_callback(" + str(int(status)) + ", '" + str(completion_candidates) + "', " + str(length) + ")" 118 | ) 119 | 120 | if success: 121 | candidate_list = [] 122 | for result in code_completion_results: 123 | kind = self._ast_node_id_to_vim_complete_item_kind(ClangParser.to_ast_node_id(result.kind)) 124 | if kind != '': 125 | result_type, candidate, params = self._extract_chunks(result.string) 126 | if candidate: 127 | candidate_list.append( 128 | self._create_vim_complete_item( 129 | candidate + '(' + ')' if kind == 'f' else candidate, 130 | candidate + '(' + ', '.join(params) + ')' if kind == 'f' else candidate, 131 | kind, 132 | result_type 133 | ) 134 | ) 135 | else: 136 | logging.error('Cannot handle following cursor kind: {0}'.format(result.kind)) 137 | 138 | with open(self.code_complete_candidates_output, 'w') as f: 139 | f.writelines(', '.join(str(item) for item in candidate_list)) 140 | 141 | call_vim_rpc(success, self.code_complete_candidates_output, len(candidate_list)) 142 | logging.info('Found {0} candidates.'.format(len(candidate_list))) 143 | else: 144 | call_vim_rpc(success, [], 0) 145 | -------------------------------------------------------------------------------- /lib/services/disassembly/disassembly.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import tempfile 4 | from utils import Utils 5 | from cxxd.service_plugin import ServicePlugin 6 | from cxxd.services.disassembly_service import DisassemblyRequestId 7 | 8 | class VimDisassembly(ServicePlugin): 9 | def __init__(self, servername): 10 | self.servername = servername 11 | self.disassembly_target_candidates_output = os.path.join(tempfile.gettempdir(), self.servername + 'disassembly_target_candidates') 12 | self.disassembly_symbol_candidates_output = os.path.join(tempfile.gettempdir(), self.servername + 'disassembly_symbol_candidates') 13 | 14 | def startup_callback(self, success, payload, startup_payload): 15 | Utils.call_vim_remote_function(self.servername, "cxxd#services#disassembly#start_callback(" + str(int(success)) + ")") 16 | 17 | def shutdown_callback(self, success, payload, shutdown_payload): 18 | reply_with_callback = bool(payload[0]) 19 | if reply_with_callback: 20 | Utils.call_vim_remote_function(self.servername, "cxxd#services#disassembly#stop_callback(" + str(int(success)) + ")") 21 | 22 | def __call__(self, success, payload, args): 23 | disassembly_op_id = int(payload[0]) 24 | if disassembly_op_id == DisassemblyRequestId.LIST_TARGETS: 25 | self._list_targets(success, payload, args) 26 | elif disassembly_op_id == DisassemblyRequestId.LIST_SYMBOL_CANDIDATES: 27 | self._list_symbol_candidates(success, payload, args) 28 | elif disassembly_op_id == DisassemblyRequestId.DISASSEMBLE: 29 | self._disassemble(success, payload, args) 30 | elif disassembly_op_id == DisassemblyRequestId.ASM_INSTRUCTION_INFO: 31 | self._info_on_asm_instruction(success, payload, args) 32 | else: 33 | logging.error('Invalid disassembly request ID: {0}'.format(disassembly_op_id)) 34 | 35 | def _list_targets(self, success, payload, args): 36 | target_candidates = args 37 | with open(self.disassembly_target_candidates_output, 'w') as f: 38 | f.writelines(', '.join(str("'" + item.strip() + "'") for item in target_candidates)) 39 | Utils.call_vim_remote_function( 40 | self.servername, 41 | "cxxd#services#disassembly#pick_target_callback(" + str(int(success)) + ", '" + str(self.disassembly_target_candidates_output) + "', " + str(len(target_candidates)) + ")" 42 | ) 43 | 44 | def _list_symbol_candidates(self, success, payload, args): 45 | def make_popup_item(symbol): 46 | return symbol.demangled_name + ' ' + \ 47 | symbol.type + ' ' + \ 48 | symbol.addr + ' ' + \ 49 | symbol.offset + ' ' + \ 50 | symbol.location 51 | 52 | symbol_candidates = args 53 | with open(self.disassembly_symbol_candidates_output, 'w') as f: 54 | f.writelines(', '.join(str("'" + make_popup_item(item) + "'") for item in symbol_candidates)) 55 | Utils.call_vim_remote_function( 56 | self.servername, 57 | "cxxd#services#disassembly#pick_symbol_callback(" + str(int(success)) + ", '" + str(self.disassembly_symbol_candidates_output) + "', " + str(len(symbol_candidates)) + ")" 58 | ) 59 | 60 | def _disassemble(self, success, payload, args): 61 | disassembly_output, addr, offset = args 62 | Utils.call_vim_remote_function( 63 | self.servername, 64 | "cxxd#services#disassembly#run_callback(" + str(int(success)) + ", '" + str(disassembly_output) + "', '" + str(addr) + "', '" + str(offset) + "')" 65 | ) 66 | 67 | def _info_on_asm_instruction(self, success, payload, args): 68 | tooltip = args[0] 69 | description = args[1] 70 | url = args[2] 71 | Utils.call_vim_remote_function( 72 | self.servername, 73 | "cxxd#services#disassembly#asm_instruction_info_callback(" + str(int(success)) + ", '" + str(tooltip) + "', '" + str(description) + "', '" + str(url) + "')" 74 | ) 75 | -------------------------------------------------------------------------------- /lib/services/project_builder/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/project_builder/__init__.py -------------------------------------------------------------------------------- /lib/services/project_builder/project_builder.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | from cxxd.service_plugin import ServicePlugin 4 | 5 | class VimProjectBuilder(ServicePlugin): 6 | def __init__(self, servername): 7 | self.servername = servername 8 | 9 | def startup_callback(self, success, payload, startup_payload): 10 | output_build_file = str(startup_payload[0]) 11 | Utils.call_vim_remote_function(self.servername, "cxxd#services#project_builder#start_callback(" + str(int(success)) + ", '" + output_build_file + "')") 12 | 13 | def shutdown_callback(self, success, payload, shutdown_payload): 14 | reply_with_callback = bool(payload[0]) 15 | if reply_with_callback: 16 | Utils.call_vim_remote_function(self.servername, "cxxd#services#project_builder#stop_callback(" + str(int(success)) + ")") 17 | 18 | def __call__(self, success, payload, args): 19 | def call_vim_rpc(status, duration, build_exit_code, output): 20 | Utils.call_vim_remote_function( 21 | self.servername, 22 | "cxxd#services#project_builder#run_callback(" + str(int(status)) + ", '" + str(duration) + "', " + str(build_exit_code) + ", '" + output + "')" 23 | ) 24 | 25 | if success: 26 | output, build_exit_code, duration = args 27 | call_vim_rpc(success, duration, build_exit_code, output) 28 | else: 29 | logging.error("Something went wrong with project-builder ... success={0}, payload={1}, args={2}.".format(success, payload, args)) 30 | call_vim_rpc(success, 0, 0, '') 31 | -------------------------------------------------------------------------------- /lib/services/source_code_model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/diagnostics/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/diagnostics/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/diagnostics/diagnostics.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | 4 | class VimDiagnostics: 5 | def __init__(self, servername): 6 | self.servername = servername 7 | 8 | def __call__(self, success, payload, args): 9 | def clang_severity_to_quickfix_type(severity): 10 | # Clang severity | Vim Quickfix type 11 | # ---------------------------------- 12 | # Ignored = 0 I (info) 13 | # Note = 1 I (info) 14 | # Warning = 2 W (warning) 15 | # Error = 3 E (error) 16 | # Fatal = 4 E (error) 17 | # ---------------------------------- 18 | if severity == 0: 19 | return 'I' 20 | elif severity == 1: 21 | return 'I' 22 | elif severity == 2: 23 | return 'W' 24 | elif severity >= 3: 25 | return 'E' 26 | return '0' 27 | 28 | def diag_callback(filename, line, column, spelling, severity, category_number, category_name, fixits_iterator, diagnostics): 29 | def fixits_callback(range, value, fixit_hint): 30 | fixit_hint.append( 31 | "Try using '" + str(value) + "' instead (col" + str(range.start.column) + " -> col" + str(range.end.column) + ")" 32 | ) 33 | # TODO How to handle multiline quickfix entries? It would be nice show each fixit in its own line. 34 | 35 | fixit_hint = [] 36 | diagnostics.append( 37 | "{'filename': '" + str(filename) + "', " + 38 | "'lnum': '" + str(line) + "', " + 39 | "'col': '" + str(column) + "', " + 40 | "'type': '" + clang_severity_to_quickfix_type(severity) + "', " + 41 | "'text': '" + category_name + " | " + spelling.replace("'", r"") + "'}" 42 | ) 43 | fixit_visitor(fixits_iterator, fixits_callback, fixit_hint) 44 | diagnostics.append( 45 | "{'filename': '" + str(filename) + "', " + 46 | "'lnum': '" + str(line) + "', " + 47 | "'col': '" + str(column) + "', " + 48 | "'type': 'I', " + 49 | "'text': 'Hint: " + str(' '.join(fixit_hint)).replace("'", r"") + "'}" 50 | ) 51 | 52 | vim_diagnostics = [] 53 | if success: 54 | diagnostics_iterator, diagnostics_visitor, fixit_visitor = args 55 | diagnostics_visitor(diagnostics_iterator, diag_callback, vim_diagnostics) 56 | else: 57 | logging.error('Something went wrong in diagnostics service ... Diagnostics not available. Payload={0}'.format(payload)) 58 | 59 | Utils.call_vim_remote_function( 60 | self.servername, 61 | "cxxd#services#source_code_model#diagnostics#run_callback(" + str(int(success)) + ", " + str(vim_diagnostics).replace('"', r"") + ")" 62 | ) 63 | 64 | logging.debug("Diagnostics: " + str(vim_diagnostics)) 65 | -------------------------------------------------------------------------------- /lib/services/source_code_model/go_to_definition/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/go_to_definition/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/go_to_definition/go_to_definition.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | 4 | class VimGoToDefinition: 5 | def __init__(self, servername): 6 | self.servername = servername 7 | 8 | def __call__(self, success, payload, definition): 9 | def call_vim_rpc(status, filename, line, column): 10 | Utils.call_vim_remote_function( 11 | self.servername, 12 | "cxxd#services#source_code_model#go_to_definition#run_callback(" + str(int(status)) + ", '" + filename + "', " + str(line) + ", " + str(column) + ")" 13 | ) 14 | 15 | if success: 16 | filename, line, column = definition 17 | call_vim_rpc(success, filename, line, column) 18 | logging.info('Definition found at {0} [{1}, {2}]'.format(filename, line, column)) 19 | else: 20 | call_vim_rpc(success, '', 0, 0) 21 | logging.error('Something went wrong in go-to-definition service ... Definition not found. Payload = {0}'.format(payload)) 22 | -------------------------------------------------------------------------------- /lib/services/source_code_model/go_to_include/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/go_to_include/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/go_to_include/go_to_include.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | 4 | class VimGoToInclude: 5 | def __init__(self, servername): 6 | self.servername = servername 7 | 8 | def __call__(self, success, payload, include): 9 | def call_vim_rpc(status, include): 10 | Utils.call_vim_remote_function( 11 | self.servername, 12 | "cxxd#services#source_code_model#go_to_include#run_callback(" + str(int(status)) + ", '" + include + "')" 13 | ) 14 | 15 | if success: 16 | call_vim_rpc(success, include) 17 | logging.info("Include filename={0}".format(include)) 18 | else: 19 | call_vim_rpc(success, '') 20 | logging.error('Something went wrong in go-to-include service ... Include not found. Payload={0}'.format(payload)) 21 | -------------------------------------------------------------------------------- /lib/services/source_code_model/indexer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/indexer/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/indexer/indexer.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import tempfile 4 | from cxxd.services.source_code_model.indexer.clang_indexer import SourceCodeModelIndexerRequestId 5 | from utils import Utils 6 | 7 | class VimIndexer: 8 | def __init__(self, servername): 9 | self.servername = servername 10 | self.find_all_references_output = os.path.join(tempfile.gettempdir(), self.servername + 'find_all_references') 11 | self.fetch_all_diagnostics_output = os.path.join(tempfile.gettempdir(), self.servername + 'fetch_all_diagnostics') 12 | self.op = { 13 | SourceCodeModelIndexerRequestId.RUN_ON_SINGLE_FILE : self.__run_on_single_file, 14 | SourceCodeModelIndexerRequestId.RUN_ON_DIRECTORY : self.__run_on_directory, 15 | SourceCodeModelIndexerRequestId.DROP_SINGLE_FILE : self.__drop_single_file, 16 | SourceCodeModelIndexerRequestId.DROP_ALL : self.__drop_all, 17 | SourceCodeModelIndexerRequestId.FIND_ALL_REFERENCES : self.__find_all_references, 18 | SourceCodeModelIndexerRequestId.FETCH_ALL_DIAGNOSTICS : self.__fetch_all_diagnostics, 19 | } 20 | 21 | def __call__(self, success, payload, args): 22 | self.op.get(int(payload[1]), self.__unknown_op)(success, args) 23 | 24 | def __unknown_op(self, success, args): 25 | logging.error("Unknown operation triggered! Valid operations are: {0}".format(self.op)) 26 | 27 | def __run_on_single_file(self, success, args): 28 | Utils.call_vim_remote_function( 29 | self.servername, 30 | "cxxd#services#source_code_model#indexer#run_on_single_file_callback(" + str(int(success)) + ")" 31 | ) 32 | 33 | def __run_on_directory(self, success, args): 34 | Utils.call_vim_remote_function( 35 | self.servername, 36 | "cxxd#services#source_code_model#indexer#run_on_directory_callback(" + str(int(success)) + ")" 37 | ) 38 | 39 | def __drop_single_file(self, success, args): 40 | Utils.call_vim_remote_function( 41 | self.servername, 42 | "cxxd#services#source_code_model#indexer#drop_single_file_callback(" + str(int(success)) + ")" 43 | ) 44 | 45 | def __drop_all(self, success, args): 46 | Utils.call_vim_remote_function( 47 | self.servername, "cxxd#services#source_code_model#indexer#drop_all_callback(" + str(int(success)) + ")" 48 | ) 49 | 50 | def __find_all_references(self, success, references): 51 | quickfix_list = [] 52 | for ref in references: 53 | filename, line, column, context = ref 54 | quickfix_list.append( 55 | "{'filename': '" + filename + "', " + 56 | "'lnum': '" + str(line) + "', " + 57 | "'col': '" + str(column) + "', " + 58 | "'type': 'I', " + 59 | "'text': '" + context.replace("'", r"''").rstrip() + "'}" 60 | ) 61 | 62 | with open(self.find_all_references_output, 'w') as f: 63 | f.writelines(', '.join(item for item in quickfix_list)) 64 | 65 | Utils.call_vim_remote_function( 66 | self.servername, 67 | "cxxd#services#source_code_model#indexer#find_all_references_callback(" + str(int(success)) + ", '" + self.find_all_references_output + "')" 68 | ) 69 | logging.debug("References: " + str(quickfix_list)) 70 | 71 | def __fetch_all_diagnostics(self, success, diagnostics): 72 | def clang_severity_to_quickfix_type(severity): 73 | # Clang severity | Vim Quickfix type 74 | # ---------------------------------- 75 | # Ignored = 0 I (info) 76 | # Note = 1 I (info) 77 | # Warning = 2 W (warning) 78 | # Error = 3 E (error) 79 | # Fatal = 4 E (error) 80 | # ---------------------------------- 81 | if severity == 0: 82 | return 'I' 83 | elif severity == 1: 84 | return 'I' 85 | elif severity == 2: 86 | return 'W' 87 | elif severity >= 3: 88 | return 'E' 89 | return '0' 90 | 91 | quickfix_list = [] 92 | for diag in diagnostics: 93 | filename, line, column, description, severity = diag 94 | quickfix_list.append( 95 | "{'filename': '" + filename + "', " + 96 | "'lnum': '" + str(line) + "', " + 97 | "'col': '" + str(column) + "', " + 98 | "'type': '" + clang_severity_to_quickfix_type(severity) + "', " + 99 | "'text': '" + description.replace("'", r"''").rstrip() + "'}" 100 | ) 101 | 102 | with open(self.fetch_all_diagnostics_output, 'w') as f: 103 | f.writelines(', '.join(item for item in quickfix_list)) 104 | 105 | Utils.call_vim_remote_function( 106 | self.servername, 107 | "cxxd#services#source_code_model#indexer#fetch_all_diagnostics_callback(" + str(int(success)) + ", '" + self.fetch_all_diagnostics_output + "')" 108 | ) 109 | logging.debug("Diagnostics: " + str(quickfix_list)) 110 | -------------------------------------------------------------------------------- /lib/services/source_code_model/semantic_syntax_highlight/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/semantic_syntax_highlight/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/semantic_syntax_highlight/semantic_syntax_highlight.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import time 3 | from utils import Utils 4 | from cxxd.parser.ast_node_identifier import ASTNodeId 5 | from cxxd.parser.ctags_parser import CtagsTokenizer 6 | 7 | class VimSemanticSyntaxHighlight: 8 | def __init__(self, servername, output_syntax_file): 9 | self.servername = servername 10 | self.output_syntax_file = output_syntax_file 11 | 12 | def __call__(self, success, payload, args): 13 | class VimHlMatch: 14 | def __init__(self, group, line, column, length): 15 | self.group = group 16 | self.line = line 17 | self.column = column 18 | self.length = length 19 | 20 | def __hash__(self): 21 | return hash((self.group, self.line, self.column, self.length)) 22 | 23 | def __eq__(self, other): 24 | if self.group == other.group and self.line == other.line and self.column == other.column and self.length == other.length: 25 | return True 26 | return False 27 | 28 | def create_clearmatches_pattern(): 29 | return "call clearmatches()" 30 | 31 | def create_matchaddpos_pattern(hl_match): 32 | return "call matchaddpos('" + hl_match.group + "', [[" + str(hl_match.line) + ", " + str(hl_match.column) + ", " + str(hl_match.length) + "]])" 33 | 34 | def callback(ast_node_id, ast_node_name, ast_node_line, ast_node_column, syntax): 35 | syntax.add( 36 | VimHlMatch( 37 | VimSemanticSyntaxHighlight.__tag_id_to_vim_syntax_group(ast_node_id), 38 | ast_node_line, 39 | ast_node_column, 40 | len(ast_node_name) 41 | ) 42 | ) 43 | 44 | def call_vim_rpc(status, filename, syntax_file): 45 | Utils.call_vim_remote_function( 46 | self.servername, 47 | "cxxd#services#source_code_model#semantic_syntax_highlight#run_callback(" + str(int(status)) + ", '" + filename + "'" + ", '" + syntax_file + "')" 48 | ) 49 | 50 | if success: 51 | # Unpack the parameters 52 | tunit, line_begin, line_end, traverse = args 53 | 54 | # Build Vim syntax highlight rules 55 | vim_syntax_hl_patterns = set() 56 | traverse(tunit, line_begin, line_end, callback, vim_syntax_hl_patterns) 57 | 58 | # Write Vim syntax file 59 | with open(self.output_syntax_file, "w") as vim_syntax_file: 60 | vim_syntax_file.write(create_clearmatches_pattern() + '\n') # TODO 'vim_syntax_hl_patterns' is an unordered set and therefore resulting 61 | for hl_pattern in vim_syntax_hl_patterns: # vim syntax file will contain 'matchaddpos' entries which are not 62 | vim_syntax_file.write(create_matchaddpos_pattern(hl_pattern) + '\n') # going to be ordered by [line, column]. It needs to be checked if 63 | 64 | # Apply newly generated syntax rules 65 | call_vim_rpc(success, payload[1], self.output_syntax_file) 66 | else: 67 | call_vim_rpc(success, '', '') 68 | logging.error('Something went wrong in semantic syntax highlighting service ... Payload={0} Args={1}'.format(payload, args)) 69 | 70 | def generate_vim_syntax_file_from_ctags(self, filename): 71 | # Generate the tags 72 | output_tag_file = "/tmp/syntax_file.vim" 73 | tokenizer = CtagsTokenizer(output_tag_file) 74 | tokenizer.run(filename) 75 | 76 | # Generate the vim syntax file 77 | tags_db = None 78 | try: 79 | with open(output_tag_file) as tags_db: 80 | # Build Vim syntax highlight rules 81 | vim_highlight_rules = set() 82 | for line in tags_db: 83 | if not tokenizer.is_header(line): 84 | highlight_rule = VimSemanticSyntaxHighlight.__tag_id_to_vim_syntax_group(tokenizer.get_token_id(line)) + " " + tokenizer.get_token_name(line) 85 | vim_highlight_rules.add(highlight_rule) 86 | 87 | vim_syntax_hl_patterns = [] 88 | for rule in vim_highlight_rules: 89 | vim_syntax_hl_patterns.append("syntax keyword " + rule + "\n") 90 | 91 | # Write syntax file 92 | with open(self.output_syntax_file, "w") as vim_syntax_file: 93 | vim_syntax_file.writelines(vim_syntax_hl_patterns) 94 | finally: 95 | if tags_db is not None: 96 | tags_db.close() 97 | 98 | @staticmethod 99 | def __tag_id_to_vim_syntax_group(tag_identifier): 100 | if tag_identifier == ASTNodeId.getNamespaceId(): 101 | return "CxxdNamespace" 102 | if tag_identifier == ASTNodeId.getNamespaceAliasId(): 103 | return "CxxdNamespaceAlias" 104 | if tag_identifier == ASTNodeId.getClassId(): 105 | return "CxxdClass" 106 | if tag_identifier == ASTNodeId.getStructId(): 107 | return "CxxdStructure" 108 | if tag_identifier == ASTNodeId.getEnumId(): 109 | return "CxxdEnum" 110 | if tag_identifier == ASTNodeId.getEnumValueId(): 111 | return "CxxdEnumValue" 112 | if tag_identifier == ASTNodeId.getUnionId(): 113 | return "CxxdUnion" 114 | if tag_identifier == ASTNodeId.getFieldId(): 115 | return "CxxdField" 116 | if tag_identifier == ASTNodeId.getLocalVariableId(): 117 | return "CxxdLocalVariable" 118 | if tag_identifier == ASTNodeId.getFunctionId(): 119 | return "CxxdFunction" 120 | if tag_identifier == ASTNodeId.getMethodId(): 121 | return "CxxdMethod" 122 | if tag_identifier == ASTNodeId.getFunctionParameterId(): 123 | return "CxxdFunctionParameter" 124 | if tag_identifier == ASTNodeId.getTemplateTypeParameterId(): 125 | return "CxxdTemplateTypeParameter" 126 | if tag_identifier == ASTNodeId.getTemplateNonTypeParameterId(): 127 | return "CxxdTemplateNonTypeParameter" 128 | if tag_identifier == ASTNodeId.getTemplateTemplateParameterId(): 129 | return "CxxdTemplateTemplateParameter" 130 | if tag_identifier == ASTNodeId.getMacroDefinitionId(): 131 | return "CxxdMacroDefinition" 132 | if tag_identifier == ASTNodeId.getMacroInstantiationId(): 133 | return "CxxdMacroInstantiation" 134 | if tag_identifier == ASTNodeId.getTypedefId(): 135 | return "CxxdTypedef" 136 | if tag_identifier == ASTNodeId.getUsingDirectiveId(): 137 | return "CxxdUsingDirective" 138 | if tag_identifier == ASTNodeId.getUsingDeclarationId(): 139 | return "CxxdUsingDeclaration" 140 | 141 | def main(): 142 | import argparse 143 | parser = argparse.ArgumentParser() 144 | parser.add_argument("filename", help="source code file to generate the source code highlighting for") 145 | parser.add_argument("output_syntax_file", help="resulting Vim syntax file") 146 | args = parser.parse_args() 147 | args_dict = vars(args) 148 | 149 | vimHighlighter = VimSemanticSyntaxHighlight(args.output_syntax_file) 150 | vimHighlighter(args.filename, ['']) 151 | 152 | if __name__ == "__main__": 153 | main() 154 | 155 | -------------------------------------------------------------------------------- /lib/services/source_code_model/source_code_model.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import tempfile 3 | import os 4 | from utils import Utils 5 | from cxxd.service_plugin import ServicePlugin 6 | from cxxd.services.source_code_model_service import SourceCodeModelSubServiceId 7 | from . indexer.indexer import VimIndexer 8 | from . semantic_syntax_highlight.semantic_syntax_highlight import VimSemanticSyntaxHighlight 9 | from . diagnostics.diagnostics import VimDiagnostics 10 | from . type_deduction.type_deduction import VimTypeDeduction 11 | from . go_to_definition.go_to_definition import VimGoToDefinition 12 | from . go_to_include.go_to_include import VimGoToInclude 13 | 14 | class VimSourceCodeModel(ServicePlugin): 15 | def __init__(self, servername): 16 | self.servername = servername 17 | self.indexer = VimIndexer(self.servername) 18 | self.semantic_syntax_higlight = VimSemanticSyntaxHighlight(self.servername, tempfile.gettempdir() + os.sep + self.servername + '_syntax_file.vim') 19 | self.diagnostics = VimDiagnostics(self.servername) 20 | self.type_deduction = VimTypeDeduction(self.servername) 21 | self.go_to_definition = VimGoToDefinition(self.servername) 22 | self.go_to_include = VimGoToInclude(self.servername) 23 | 24 | def startup_callback(self, success, payload, startup_payload): 25 | Utils.call_vim_remote_function( 26 | self.servername, 27 | "cxxd#services#source_code_model#start_callback(" + str(int(success)) + ")" 28 | ) 29 | 30 | def shutdown_callback(self, success, payload, shutdown_payload): 31 | reply_with_callback = bool(payload[0]) 32 | if reply_with_callback: 33 | Utils.call_vim_remote_function( 34 | self.servername, 35 | "cxxd#services#source_code_model#stop_callback(" + str(int(success)) + ")" 36 | ) 37 | 38 | def __call__(self, success, payload, args): 39 | source_code_model_service_id = int(payload[0]) 40 | if source_code_model_service_id == SourceCodeModelSubServiceId.INDEXER: 41 | self.indexer(success, payload, args) 42 | elif source_code_model_service_id == SourceCodeModelSubServiceId.SEMANTIC_SYNTAX_HIGHLIGHT: 43 | self.semantic_syntax_higlight(success, payload, args) 44 | elif source_code_model_service_id == SourceCodeModelSubServiceId.DIAGNOSTICS: 45 | self.diagnostics(success, payload, args) 46 | elif source_code_model_service_id == SourceCodeModelSubServiceId.TYPE_DEDUCTION: 47 | self.type_deduction(success, payload, args) 48 | elif source_code_model_service_id == SourceCodeModelSubServiceId.GO_TO_DEFINITION: 49 | self.go_to_definition(success, payload, args) 50 | elif source_code_model_service_id == SourceCodeModelSubServiceId.GO_TO_INCLUDE: 51 | self.go_to_include(success, payload, args) 52 | else: 53 | logging.error('Invalid source code model service id!') 54 | -------------------------------------------------------------------------------- /lib/services/source_code_model/type_deduction/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBakamovic/cxxd-vim/3aa95c7743fb93ddb5de9023a501a1b2cf8126f3/lib/services/source_code_model/type_deduction/__init__.py -------------------------------------------------------------------------------- /lib/services/source_code_model/type_deduction/type_deduction.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from utils import Utils 3 | 4 | class VimTypeDeduction: 5 | def __init__(self, servername): 6 | self.servername = servername 7 | 8 | def __call__(self, success, payload, type_spelling): 9 | def call_vim_rpc(status, type_spelling): 10 | Utils.call_vim_remote_function( 11 | self.servername, 12 | "cxxd#services#source_code_model#type_deduction#run_callback(" + str(int(status)) + ", '" + type_spelling + "')" 13 | ) 14 | 15 | if success: 16 | logging.debug("Type spelling={0}".format(type_spelling)) 17 | call_vim_rpc(success, type_spelling) 18 | else: 19 | call_vim_rpc(success, '') 20 | logging.error('Something went wrong in type deduction service ... Type has not been successfuly deducted. Payload={0}'.format(payload)) 21 | -------------------------------------------------------------------------------- /lib/utils.py: -------------------------------------------------------------------------------- 1 | import socket 2 | from subprocess import call 3 | import shlex 4 | 5 | file_type_dict = { 6 | 'Cxx': ['.c', '.cpp', '.cc', '.h', '.hh', '.hpp'], 7 | 'Java': ['.java'] } 8 | 9 | class Utils(): 10 | @staticmethod 11 | def file_type_to_programming_language(file_type): 12 | for lang, file_types in file_type_dict.items(): 13 | if file_type in file_types: 14 | return lang 15 | return '' 16 | 17 | @staticmethod 18 | def programming_language_to_extension(programming_language): 19 | return file_type_dict.get(programming_language, '') 20 | 21 | @staticmethod 22 | def send_vim_remote_command(vim_instance, command): 23 | cmd = 'gvim --servername ' + vim_instance + ' --remote-send "' + command + '"' 24 | return call(shlex.split(cmd)) 25 | 26 | @staticmethod 27 | def call_vim_remote_function(vim_instance, function): 28 | cmd = 'gvim --servername ' + vim_instance + ' --remote-expr "' + function + '"' 29 | return call(shlex.split(cmd)) 30 | 31 | @staticmethod 32 | def is_port_available(port): 33 | s = socket.socket() 34 | try: 35 | s.bind(('localhost', port)) 36 | s.close() 37 | return True 38 | except socket.error as msg: 39 | s.close() 40 | return False 41 | 42 | @staticmethod 43 | def get_available_port(port_begin, port_end): 44 | for port in range(port_begin, port_end): 45 | if Utils.is_port_available(port) == True: 46 | return port 47 | return -1 48 | -------------------------------------------------------------------------------- /make_color.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import argparse 4 | 5 | cxxd_vim_specific_highlight_links = """ 6 | hi! link NamespaceTag Identifier 7 | hi! link NamespaceAliasTag Identifier 8 | hi! link ClassTag Type 9 | hi! link StructureTag Type 10 | hi! link UnionTag Type 11 | hi! link EnumTag Type 12 | hi! link EnumValueTag Constant 13 | hi! link FieldTag Identifier 14 | hi! link LocalVariableTag Identifier 15 | hi! link FunctionParameterTag Identifier 16 | hi! link MethodTag Function 17 | hi! link FunctionTag Function 18 | hi! link TemplateTypeParameterTag Type 19 | hi! link TemplateNonTypeParameterTag Type 20 | hi! link TemplateTemplateParameterTag Type 21 | hi! link MacroDefinitionTag PreProc 22 | hi! link MacroInstantiationTag PreProc 23 | hi! link TypedefTag Type 24 | hi! link UsingDirectiveTag Identifier 25 | hi! link UsingDeclarationTag Type 26 | """ 27 | 28 | def main(): 29 | parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, \ 30 | description='cxxd has a semantic understanding of the C and C++ code. Because of that\n' 31 | 'it can generate Vim colorscheme tags/groups at much more finer level than what\n' 32 | 'vanilla Vim colorscheme will support. This is called semantic syntax highlighting.\n' 33 | '\n' 34 | 'This tool is envisioned to help convert your favorite Vim colorscheme into a format\n' 35 | 'so that cxxd-vim can take advantage of semantic syntax highlighting support built into\n' 36 | 'a cxxd.\n' 37 | '\n' 38 | 'What will it basically do is that it will link special syntax highlighting groups generated\n' 39 | 'by the cxxd to the groups defined by Vim as "preferred" so it shouldn\'t be destructive by any\n' 40 | 'means.\n' 41 | '\n' 42 | 'Preferred groups are only handful and source-code wise those include only [Identifier, \n' 43 | 'Statement, PreProc, Constant, Type]. This is why conversion is rather conservative\n' 44 | 'and it may or may not end up with the best results. It mostly depends on how well and detailed \n' 45 | 'the given colorscheme is implemented and/or tweaked towards the C and C++ syntax.\n' 46 | '\n' 47 | 'New highlighting groups that will be linked against the "preferred" ones are:\n' 48 | '{}'.format(cxxd_vim_specific_highlight_links)) 49 | parser.add_argument('colorscheme', nargs='+', help='Existing Vim colorscheme to be converted into a semantic syntax highlighting format.') 50 | args = parser.parse_args() 51 | 52 | for c in args.colorscheme: 53 | with open(c, 'r') as f: 54 | buf = f.readlines() 55 | with open(c, 'w') as f: 56 | for line in buf: 57 | if line == "hi clear\n": 58 | line = line + cxxd_vim_specific_highlight_links + '\n' 59 | f.write(line) 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /plugin/cxxd.vim: -------------------------------------------------------------------------------- 1 | " 2 | " Sanity checks 3 | " 4 | if exists("g:loaded_cxxdvim") 5 | finish 6 | else 7 | if !has("clientserver") 8 | echohl WarningMsg | 9 | \ echoerr "cxxd-vim requires (G)Vim compiled with 'clientserver' feature.". 10 | \ " TL;DR Use GVim. Non-gui versions of Vim are usually not distributed with 'clientserver' feature compiled in." | 11 | \ echohl None 12 | call feedkeys("\") 13 | finish 14 | elseif !has("python3") 15 | echohl WarningMsg | 16 | \ echoerr "cxxd-vim requires (G)Vim compiled with 'python' feature." | 17 | \ echohl None 18 | call feedkeys("\") 19 | finish 20 | endif 21 | endif 22 | let g:loaded_cxxdvim = 1 23 | 24 | 25 | " 26 | " Store cpo 27 | " 28 | let s:save_cpo = &cpo 29 | set cpo&vim 30 | 31 | " 32 | " Cxxd code-completion sorting strategies 33 | " Code-completion candidates may be sorted with different strategies: 34 | " (1) By priority (which is given & deduced by Clang code-completion engine). 35 | " (2) By symbol kind (same symbol kinds will be grouped together; e.g. functions, variables, methods, etc.). 36 | " (3) Alphabetically. 37 | " 38 | let g:cxxd_code_completion_sorting_strategies = { 39 | \ 'priority' : 0, 40 | \ 'kind' : 1, 41 | \ 'alphabet' : 2, 42 | \} 43 | 44 | " 45 | " Cxxd fetch-all-diagnostics sorting strategies 46 | " Reported diagnostics may be sorted with different strategies: 47 | " (1) No sorting. 48 | " (2) By diagnostics severity (ascending order). 49 | " (3) By diagnostics severity (descending order). 50 | " (4) Alphabetically by filenames. 51 | " 52 | let g:cxxd_fetch_all_diagnostics_sorting_strategies = { 53 | \ 'none' : 0, 54 | \ 'severity_asc' : 1, 55 | \ 'severity_desc' : 2, 56 | \ 'filename' : 3, 57 | \} 58 | 59 | " 60 | " Cxxd services definition 61 | " 62 | let g:cxxd_src_code_model = { 63 | \ 'enabled' : 1, 64 | \ 'started' : 0, 65 | \ 'services' : { 66 | \ 'indexer' : { 'enabled' : 1 }, 67 | \ 'semantic_syntax_highlight' : { 'enabled' : 1 }, 68 | \ 'diagnostics' : { 'enabled' : 1 }, 69 | \ 'type_deduction' : { 'enabled' : 1 }, 70 | \ 'go_to_definition' : { 'enabled' : 1 }, 71 | \ 'go_to_include' : { 'enabled' : 1 }, 72 | \ 'code_completion' : { 73 | \ 'enabled' : 1, 74 | \ 'sorting_strategy' : g:cxxd_code_completion_sorting_strategies['priority'], 75 | \ } 76 | \ } 77 | \} 78 | 79 | let g:cxxd_code_completion = { 80 | \ 'enabled' : 1, 81 | \ 'started' : 0, 82 | \} 83 | 84 | let g:cxxd_project_builder = { 85 | \ 'enabled' : 1, 86 | \ 'started' : 0, 87 | \} 88 | 89 | let g:cxxd_clang_format = { 90 | \ 'enabled' : 1, 91 | \ 'started' : 0, 92 | \ 'config' : '.clang-format' 93 | \} 94 | 95 | let g:cxxd_clang_tidy = { 96 | \ 'enabled' : 1, 97 | \ 'started' : 0, 98 | \ 'config' : '.clang-tidy' 99 | \} 100 | 101 | let g:cxxd_disassembly = { 102 | \ 'enabled' : 1, 103 | \ 'started' : 0, 104 | \} 105 | 106 | let g:cxxd_available_services = [ 107 | \ g:cxxd_src_code_model, 108 | \ g:cxxd_project_builder, 109 | \ g:cxxd_clang_format, 110 | \ g:cxxd_clang_tidy, 111 | \ g:cxxd_disassembly 112 | \] 113 | 114 | 115 | " 116 | " Cxxd services integration 117 | " 118 | augroup cxxd_init_deinit 119 | autocmd! 120 | autocmd VimLeave * call cxxd#server#stop(v:false) 121 | autocmd VimEnter,WinEnter * call cxxd#utils#init_window_specific_vars() 122 | augroup END 123 | 124 | augroup cxxd_handle_window_specific_vars 125 | autocmd! 126 | autocmd TextChangedI *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#utils#modifications_handler_i(winnr()) 127 | autocmd TextChangedP *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#utils#modifications_handler_p(winnr()) 128 | autocmd CursorHold,CursorHoldI *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#utils#modifications_handler(winnr()) | call cxxd#utils#viewport_handler(winnr(), line('w0'), line('w$')) 129 | augroup END 130 | 131 | augroup cxxd_source_code_model_indexer 132 | autocmd! 133 | " Keeping the index of freshly modified file up to date is currently wired 134 | " through the clang-format callback. This way a racey condition between the 135 | " clang-format and source-code-indexer is addressed at the cost of less robust 136 | " solution. In future, there might be a logic implemented on the frontend side 137 | " which will, depending on the clang-format configuration, deduce whether or 138 | " not to send an indexer request to cxxd. See commit message for more details. 139 | "autocmd BufWritePost *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#source_code_model#indexer#run_on_single_file(expand('%:p')) 140 | augroup END 141 | 142 | augroup cxxd_code_completion 143 | autocmd! 144 | autocmd CursorHoldI *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#code_completion#run(expand('%:p'), line('.'), col('.')-1) 145 | autocmd TextChangedP *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#code_completion#run(expand('%:p'), line('.'), col('.')-1) 146 | autocmd BufEnter *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#code_completion#cache_warmup(expand('%:p')) 147 | augroup END 148 | 149 | augroup cxxd_source_code_model_diagnostics 150 | autocmd! 151 | autocmd CursorHold *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#source_code_model#diagnostics#run(expand('%:p')) 152 | autocmd CursorHoldI *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx if cxxd#utils#statement_finished(getline('.')[0:(col('.')+1)]) | call cxxd#services#source_code_model#diagnostics#run(expand('%:p')) | endif 153 | autocmd CompleteDone *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx if !empty(v:completed_item) | call cxxd#services#source_code_model#diagnostics#run(expand('%:p')) | endif 154 | augroup END 155 | 156 | augroup cxxd_source_code_model_semantic_syntax_highlight 157 | autocmd! 158 | autocmd CursorHold *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#source_code_model#semantic_syntax_highlight#run(expand('%:p')) 159 | autocmd CursorHoldI *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx if cxxd#utils#statement_finished(getline('.')[0:(col('.')+1)]) | call cxxd#services#source_code_model#semantic_syntax_highlight#run(expand('%:p')) | endif 160 | autocmd CompleteDone *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx if !empty(v:completed_item) | call cxxd#services#source_code_model#semantic_syntax_highlight#run(expand('%:p')) | endif 161 | augroup END 162 | 163 | augroup cxxd_clang_format 164 | autocmd! 165 | autocmd BufWritePost *.cpp,*.cxx,*.cc,*.c,*.h,*.hh,*.hpp,*.hxx call cxxd#services#clang_format#run(expand('%:p')) 166 | augroup END 167 | 168 | " 169 | " Cxxd commands 170 | " 171 | :command -nargs=+ -complete=dir CxxdStart :call cxxd#server#start() 172 | :command CxxdStop :call cxxd#server#stop(v:false) 173 | :command CxxdGoToInclude :call cxxd#services#source_code_model#go_to_include#run(expand('%:p'), line('.'), v:false) 174 | :command CxxdGoToIncludeInPreview :call cxxd#services#source_code_model#go_to_include#run(expand('%:p'), line('.'), v:true) 175 | :command CxxdGoToDefinition :call cxxd#services#source_code_model#go_to_definition#run(expand('%:p'), line('.'), col('.'), v:false) 176 | :command CxxdGoToDefinitionInPreview :call cxxd#services#source_code_model#go_to_definition#run(expand('%:p'), line('.'), col('.'), v:true) 177 | :command CxxdFindAllReferences :call cxxd#services#source_code_model#indexer#find_all_references(expand('%:p'), line('.'), col('.')) 178 | :command CxxdFetchAllDiagnostics :call cxxd#services#source_code_model#indexer#fetch_all_diagnostics(g:cxxd_fetch_all_diagnostics_sorting_strategies['none']) 179 | :command CxxdFetchAllDiagnosticsBySeverityAsc :call cxxd#services#source_code_model#indexer#fetch_all_diagnostics(g:cxxd_fetch_all_diagnostics_sorting_strategies['severity_asc']) 180 | :command CxxdFetchAllDiagnosticsBySeverityDesc :call cxxd#services#source_code_model#indexer#fetch_all_diagnostics(g:cxxd_fetch_all_diagnostics_sorting_strategies['severity_desc']) 181 | :command CxxdFetchAllDiagnosticsByAlphabet :call cxxd#services#source_code_model#indexer#fetch_all_diagnostics(g:cxxd_fetch_all_diagnostics_sorting_strategies['filename']) 182 | :command CxxdRebuildIndex :call cxxd#services#source_code_model#indexer#drop_all_and_run_on_directory() 183 | :command CxxdCodeCompletion :call cxxd#services#code_completion#run_i(expand('%:p'), line('.'), col('.')) 184 | :command CxxdAnalyzerClangTidyBuf :call cxxd#services#clang_tidy#run(expand('%:p'), v:false) 185 | :command CxxdAnalyzerClangTidyApplyFixesBuf :call cxxd#services#clang_tidy#run(expand('%:p'), v:true) 186 | :command CxxdBuildRun :call cxxd#services#project_builder#run_target() 187 | :command -nargs=+ CxxdBuildRunWithParams :call cxxd#services#project_builder#run_custom() 188 | :command CxxdDisassemblyPickTarget :call cxxd#services#disassembly#pick_target() 189 | :command CxxdDisassemblyPickSymbol :call cxxd#services#disassembly#pick_symbol(expand('%p'), line('.'), col('.')) 190 | 191 | " 192 | " Cxxd default-provided key mappings 193 | " 194 | nmap :CxxdGoToInclude | " Open file (header-include) under the cursor 195 | imap :CxxdGoToIncludei 196 | nmap :CxxdGoToIncludeInPreview | " Open file (header-include) under the cursor (preview window) 197 | imap :CxxdGoToIncludeInPreviewi 198 | nmap :vsp :CxxdGoToInclude | " Open file (header-include) under the cursor in a vertical split 199 | imap :vsp :CxxdGoToIncludei 200 | nmap :sp :CxxdGoToInclude | " Open file (header-include) under the cursor in a horizontal split 201 | imap :sp :CxxdGoToIncludei 202 | nmap :CxxdGoToDefinition | " Jump to symbol definition 203 | imap :CxxdGoToDefinitioni 204 | nmap :vsp :CxxdGoToDefinition | " Jump to symbol definition in a vertical split 205 | imap :vsp :CxxdGoToDefinitioni 206 | nmap :sp :CxxdGoToDefinition | " Jump to symbol definition in a horizontal split 207 | imap :sp :CxxdGoToDefinitioni 208 | nmap :CxxdGoToDefinitionInPreview | " Jump to symbol definition (preview window) 209 | imap :CxxdGoToDefinitionInPreviewi 210 | nmap s :CxxdFindAllReferences | " Find all references of symbol under the cursor 211 | imap s :CxxdFindAllReferencesi 212 | nmap d :CxxdFetchAllDiagnosticsBySeverityDesc | " Fetch all diagnostics sorted by severity descending 213 | imap d :CxxdFetchAllDiagnosticsBySeverityDesci 214 | imap :CxxdCodeCompletiona | " Trigger code-completion 215 | nmap r :CxxdRebuildIndex | " Rebuild symbol database index for current project 216 | imap r :CxxdRebuildIndexi 217 | nmap :CxxdAnalyzerClangTidyBuf | " Run clang-tidy over current buffer (do not apply fixes) 218 | imap :CxxdAnalyzerClangTidyBufi 219 | nmap :CxxdAnalyzerClangTidyApplyFixesBuf | " Run clang-tidy over current buffer (apply fixes) 220 | imap :CxxdAnalyzerClangTidyApplyFixesBufi 221 | nmap :CxxdBuildRun | " Build project by auto-detecting build command provided by cxxd config file 222 | imap :CxxdBuildRuni 223 | 224 | " 225 | " Important to be set to a much lower value than a default one (=4000) because some 226 | " services act upon 'CursorHoldI' event. I.e. semantic syntax highlighting, diagnostics and code completion. 227 | " 228 | set updatetime=250 229 | 230 | 231 | " 232 | " Restore cpo 233 | " 234 | let &cpo = s:save_cpo 235 | unlet s:save_cpo 236 | 237 | -------------------------------------------------------------------------------- /plugin/cxxd/server.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Our Python path has to include a parent directory of 'cxxd' submodule. 3 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 4 | python3 import os, sys, vim 5 | python3 sys.path.append(vim.eval("fnamemodify(fnamemodify(expand(':p:h'), ':h'), ':h')") + os.sep + 'lib') 6 | python3 import server 7 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 8 | " Our public interface to cxxd. 9 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 10 | python3 import cxxd.api 11 | 12 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 13 | " We need a handle to server to establish the communication. 14 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 15 | python3 server_handle = None 16 | 17 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 18 | " Function: cxxd#server#start() 19 | " Description: Starts cxxd server. 20 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 21 | function! cxxd#server#start(project_root_directory, ...) 22 | let l:project_root_directory_full_path = fnamemodify(a:project_root_directory, ':p') 23 | let l:target_configuration = '' " auto-discovery mode by default 24 | if a:0 > 0 25 | let l:target_configuration = a:1 " otherwise what user has provided to us 26 | endif 27 | python3 << EOF 28 | import os 29 | import tempfile 30 | import vim 31 | import server 32 | vim_server_name = vim.eval('v:servername') 33 | server_handle = cxxd.api.server_start( 34 | server.get_instance, 35 | vim_server_name, 36 | vim.eval('l:project_root_directory_full_path'), 37 | vim.eval('l:target_configuration'), 38 | tempfile.gettempdir() + os.sep + vim_server_name + '_server.log' 39 | ) 40 | EOF 41 | call cxxd#server#start_all_services() 42 | set ballooneval balloonexpr=cxxd#server#balloonexpr() 43 | endfunction 44 | 45 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 46 | " Function: cxxd#server#stop() 47 | " Description: Stops cxxd server. 48 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 49 | function! cxxd#server#stop(subscribe_for_shutdown_callback) 50 | python3 cxxd.api.server_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 51 | endfunction 52 | 53 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 54 | " Function: cxxd#server#start_all_services() 55 | " Description: Starts all cxxd server services. 56 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 57 | function! cxxd#server#start_all_services() 58 | call cxxd#services#source_code_model#start() 59 | call cxxd#services#clang_tidy#start() 60 | call cxxd#services#clang_format#start() 61 | call cxxd#services#project_builder#start() 62 | call cxxd#services#code_completion#start() 63 | call cxxd#services#disassembly#start() 64 | endfunction 65 | 66 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 67 | " Function: cxxd#server#stop_all_services() 68 | " Description: Stops all cxxd server services. 69 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 70 | function! cxxd#server#stop_all_services(subscribe_for_shutdown_callback) 71 | call cxxd#services#source_code_model#stop(a:subscribe_for_shutdown_callback) 72 | call cxxd#services#clang_tidy#stop(a:subscribe_for_shutdown_callback) 73 | call cxxd#services#clang_format#stop(a:subscribe_for_shutdown_callback) 74 | call cxxd#services#project_builder#stop(a:subscribe_for_shutdown_callback) 75 | call cxxd#services#code_completion#stop(a:subscribe_for_shutdown_callback) 76 | call cxxd#services#disassembly#stop(a:subscribe_for_shutdown_callback) 77 | endfunction 78 | 79 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 80 | " Function: cxxd#server#balloonexpr() 81 | " Description: Now that we have multiple services hooked onto the mouse-hover 82 | " action, we have to properly dispatch them to appropriate 83 | " service. 84 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 85 | function! cxxd#server#balloonexpr() 86 | let l:buf_ext = fnamemodify(bufname(v:beval_bufnr), ':e') 87 | if l:buf_ext == 'asm' 88 | return cxxd#services#disassembly#asm_instruction_info() 89 | else 90 | return cxxd#services#source_code_model#type_deduction#run() 91 | endif 92 | endfunction 93 | -------------------------------------------------------------------------------- /plugin/cxxd/services/clang_format.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#clang_format#start() 3 | " Description: Starts the source code formatting background service. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#clang_format#start() 6 | python3 cxxd.api.clang_format_start(server_handle) 7 | endfunction 8 | 9 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 10 | " Function: cxxd#services#clang_format#start_callback() 11 | " Description: Callback from cxxd#services#clang_format#start. 12 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 13 | function! cxxd#services#clang_format#start_callback(status) 14 | if a:status == v:true 15 | let g:cxxd_clang_format['started'] = 1 16 | else 17 | echohl WarningMsg | echomsg 'Something went wrong with clang-format service start-up. See Cxxd server log for more details!' | echohl None 18 | endif 19 | endfunction 20 | 21 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 22 | " Function: cxxd#services#clang_format#stop() 23 | " Description: Stops the source code formatting background service. 24 | " Dependency: 25 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 26 | function! cxxd#services#clang_format#stop(subscribe_for_shutdown_callback) 27 | python3 cxxd.api.clang_format_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 28 | endfunction 29 | 30 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 31 | " Function: cxxd#services#clang_format#stop_callback() 32 | " Description: Callback from cxxd#services#clang_format#stop. 33 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 34 | function! cxxd#services#clang_format#stop_callback(status) 35 | if a:status == v:true 36 | let g:cxxd_clang_format['started'] = 0 37 | else 38 | echohl WarningMsg | echomsg 'Something went wrong with clang-format service shut-down. See Cxxd server log for more details!' | echohl None 39 | endif 40 | endfunction 41 | 42 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 43 | " Function: cxxd#services#clang_format#run() 44 | " Description: Triggers the formatting on current buffer. 45 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 46 | function! cxxd#services#clang_format#run(filename) 47 | if g:cxxd_clang_format['started'] && g:cxxd_clang_format['enabled'] 48 | python3 cxxd.api.clang_format_request(server_handle, vim.eval('a:filename')) 49 | endif 50 | endfunction 51 | 52 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 53 | " Function: cxxd#services#clang_format#run_callback() 54 | " Description: Reload the buffer if we are still on the same one. 55 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 56 | function! cxxd#services#clang_format#run_callback(status, filename) 57 | if a:status == v:true 58 | " TODO Ideally, re-indexing logic shall not be client's code (frontend) responsibility. We need to enable communication 59 | " between components on Cxxd server level. 60 | call cxxd#services#source_code_model#indexer#run_on_single_file(a:filename) 61 | let l:current_buffer = expand('%:p') 62 | if l:current_buffer == a:filename 63 | execute('e') 64 | execute('checktime') 65 | endif 66 | else 67 | echohl WarningMsg | echomsg 'Something went wrong with clang-format service. See Cxxd server log for more details!' | echohl None 68 | endif 69 | endfunction 70 | -------------------------------------------------------------------------------- /plugin/cxxd/services/clang_tidy.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#clang_tidy#start() 3 | " Description: Starts the clang-tidy background service. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#clang_tidy#start() 6 | python3 cxxd.api.clang_tidy_start(server_handle) 7 | endfunction 8 | 9 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 10 | " Function: cxxd#services#clang_tidy#start_callback() 11 | " Description: Callback from cxxd#services#clang_tidy#start. 12 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 13 | function! cxxd#services#clang_tidy#start_callback(status) 14 | if a:status == v:true 15 | let g:cxxd_clang_tidy['started'] = 1 16 | else 17 | echohl WarningMsg | echomsg 'Something went wrong with clang-tidy service start-up. See Cxxd server log for more details!' | echohl None 18 | endif 19 | endfunction 20 | 21 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 22 | " Function: cxxd#services#clang_tidy#stop() 23 | " Description: Stops the clang-tidy background service. 24 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 25 | function! cxxd#services#clang_tidy#stop(subscribe_for_shutdown_callback) 26 | python3 cxxd.api.clang_tidy_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 27 | endfunction 28 | 29 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 30 | " Function: cxxd#services#clang_tidy#stop_callback() 31 | " Description: Callback from cxxd#services#clang_tidy#stop. 32 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 33 | function! cxxd#services#clang_tidy#stop_callback(status) 34 | if a:status == v:true 35 | let g:cxxd_clang_tidy['started'] = 0 36 | else 37 | echohl WarningMsg | echomsg 'Something went wrong with clang-tidy service shut-down. See Cxxd server log for more details!' | echohl None 38 | endif 39 | endfunction 40 | 41 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 42 | " Function: cxxd#services#clang_tidy#run() 43 | " Description: Triggers the clang-tidy for given filename and (optionally) applies the fixes. 44 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 45 | function! cxxd#services#clang_tidy#run(filename, apply_fixes) 46 | if g:cxxd_clang_tidy['started'] && g:cxxd_clang_tidy['enabled'] 47 | python3 cxxd.api.clang_tidy_request(server_handle, vim.eval('a:filename'), vim.eval('a:apply_fixes')) 48 | endif 49 | endfunction 50 | 51 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 52 | " Function: cxxd#services#clang_tidy#run_callback() 53 | " Description: Display the results of clang-tidy. 54 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 55 | function! cxxd#services#clang_tidy#run_callback(status, filename, fixes_applied, clang_tidy_output) 56 | if a:status == v:true 57 | if a:fixes_applied 58 | " TODO Ideally, re-indexing logic shall not be client's code (frontend) responsibility. We need to enable communication 59 | " between components on Cxxd server level. 60 | call cxxd#services#source_code_model#indexer#run_on_single_file(a:filename) 61 | endif 62 | execute('cgetfile ' . a:clang_tidy_output) 63 | execute('copen') 64 | redraw 65 | else 66 | echohl WarningMsg | echomsg 'Something went wrong with clang-tidy service. See Cxxd server log for more details!' | echohl None 67 | endif 68 | endfunction 69 | 70 | -------------------------------------------------------------------------------- /plugin/cxxd/services/code_completion.vim: -------------------------------------------------------------------------------- 1 | function! cxxd#services#code_completion#start() 2 | python3 cxxd.api.code_completion_start(server_handle) 3 | endfunction 4 | 5 | function! cxxd#services#code_completion#start_callback(status) 6 | if a:status == v:true 7 | let g:cxxd_code_completion['started'] = 1 8 | else 9 | echohl WarningMsg | echomsg 'Something went wrong with code-completion service start-up. See Cxxd server log for more details!' | echohl None 10 | endif 11 | endfunction 12 | 13 | function! cxxd#services#code_completion#stop(subscribe_for_shutdown_callback) 14 | python3 cxxd.api.code_completion_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 15 | endfunction 16 | 17 | function! cxxd#services#code_completion#stop_callback(status) 18 | if a:status == v:true 19 | let g:cxxd_code_completion['started'] = 0 20 | else 21 | echohl WarningMsg | echomsg 'Something went wrong with code-completion service shut-down. See Cxxd server log for more details!' | echohl None 22 | endif 23 | endfunction 24 | 25 | function! cxxd#services#code_completion#run(filename, line, column) 26 | if g:cxxd_code_completion['started'] && g:cxxd_code_completion['enabled'] 27 | if cxxd#utils#is_more_modifications_done(winnr()) 28 | let l:contents_filename = cxxd#utils#pick_content_filename(a:filename) 29 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 30 | python3 cxxd.api.code_complete_request( 31 | \ server_handle, 32 | \ vim.eval('a:filename'), 33 | \ vim.eval('l:contents_filename'), 34 | \ vim.eval('a:line'), 35 | \ vim.eval('a:column'), 36 | \ vim.eval('line2byte(a:line)'), 37 | \ vim.eval("g:cxxd_src_code_model['services']['code_completion']['sorting_strategy']") 38 | \ ) 39 | endif 40 | endif 41 | endfunction 42 | 43 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 44 | " Function: cxxd#services#code_completion#run_callback() 45 | " Description: Opens up the pop-up menu populated with candidate list. 46 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 47 | function! cxxd#services#code_completion#run_callback(status, code_completion_candidates, len) 48 | if a:status == v:true 49 | setlocal completeopt=menuone,noinsert,noselect 50 | setlocal complete= 51 | if a:len > 0 52 | let l:idx = cxxd#utils#last_occurence_of_non_identifier(getline('.')[0:(col('.')+1)]) 53 | if l:idx == -1 54 | let l:start_completion_col = 1 55 | else 56 | let l:start_completion_col = col('.') - l:idx 57 | endif 58 | python3 << EOF 59 | import vim 60 | with open(vim.eval('a:code_completion_candidates'), 'r') as f: 61 | vim.eval("complete(" + vim.eval('l:start_completion_col') + ", [" + f.read() + "])") 62 | EOF 63 | else 64 | call complete(col('.'), []) 65 | endif 66 | else 67 | echohl WarningMsg | echomsg 'Something went wrong with code-completion service. See Cxxd server log for more details!' | echohl None 68 | endif 69 | endfunction 70 | 71 | function! cxxd#services#code_completion#cache_warmup(filename) 72 | let l:last_line = line('$') 73 | let l:last_col = col([l:last_line, '$']) 74 | if g:cxxd_code_completion['started'] && g:cxxd_code_completion['enabled'] 75 | python3 cxxd.api.code_complete_cache_warmup_request( 76 | \ server_handle, 77 | \ vim.eval('a:filename'), 78 | \ vim.eval('l:last_line'), 79 | \ vim.eval('l:last_col') 80 | \ ) 81 | endif 82 | endfunction 83 | 84 | -------------------------------------------------------------------------------- /plugin/cxxd/services/disassembly.vim: -------------------------------------------------------------------------------- 1 | let s:target_candidates = '' 2 | let s:target_selected_idx = -1 3 | let s:target_selected = '' 4 | let s:symbol_candidates = '' 5 | let s:symbol_selected_idx = -1 6 | let s:asm_winnr = 0 7 | let s:asm_line = 0 8 | let s:asm_col = 0 9 | 10 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 11 | " Function: cxxd#services#disassembly#start() 12 | " Description: Starts the disassembly background service. 13 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 14 | function! cxxd#services#disassembly#start() 15 | if g:cxxd_disassembly['enabled'] 16 | python3 cxxd.api.disassembly_start(server_handle) 17 | endif 18 | endfunction 19 | 20 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 21 | " Function: cxxd#services#disassembly#start_callback() 22 | " Description: Callback from cxxd#services#disassembly#start. 23 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 24 | function! cxxd#services#disassembly#start_callback(status) 25 | if a:status == v:true 26 | let g:cxxd_disassembly['started'] = 1 27 | else 28 | echohl WarningMsg | echomsg 'Something went wrong with disassembly service start-up. See Cxxd server log for more details!' | echohl None 29 | endif 30 | endfunction 31 | 32 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 33 | " Function: cxxd#services#disassembly#stop() 34 | " Description: Stops the disassembly background service. 35 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 36 | function! cxxd#services#disassembly#stop(subscribe_for_shutdown_callback) 37 | if g:cxxd_disassembly['enabled'] 38 | python3 cxxd.api.disassembly_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 39 | endif 40 | endfunction 41 | 42 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 43 | " Function: cxxd#services#disassembly#stop_callback() 44 | " Description: Callback from cxxd#services#disassembly#stop. 45 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 46 | function! cxxd#services#disassembly#stop_callback(status) 47 | if a:status == v:true 48 | let g:cxxd_disassembly['started'] = 0 49 | else 50 | echohl WarningMsg | echomsg 'Something went wrong with disassembly service shut-down. See Cxxd server log for more details!' | echohl None 51 | endif 52 | endfunction 53 | 54 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 55 | " Function: cxxd#services#disassembly#pick_target() 56 | " Description: Retrieves the list of targets to pick from. 57 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 58 | function! cxxd#services#disassembly#pick_target() 59 | if g:cxxd_disassembly['started'] && g:cxxd_disassembly['enabled'] 60 | python3 cxxd.api.disassembly_list_targets(server_handle) 61 | endif 62 | endfunction 63 | 64 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 65 | " Function: cxxd#services#disassembly#pick_target_callback() 66 | " Description: Callback from cxxd#services#disassembly#pick_target. This is 67 | " This is where we present the list of targets in a popup menu 68 | " which user can use to select an entry (target of interest). 69 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 70 | function! cxxd#services#disassembly#pick_target_callback(status, target_candidates, nr_of_targets) 71 | if a:status == v:true 72 | let s:target_candidates = a:target_candidates 73 | python3 << EOF 74 | import vim 75 | min_popup_height = 10 if int(vim.eval('a:nr_of_targets')) > 10 else int(vim.eval('a:nr_of_targets')) 76 | with open(vim.eval('a:target_candidates'), 'r') as f: 77 | vim.eval("popup_menu([" + f.read() + """], 78 | #{ title: \'Select the target\', 79 | callback: 'cxxd#services#disassembly#select_target_from_pick_target_callback', 80 | highlight: 'Question', 81 | filter: 's:popup_filter', 82 | minheight: """ + str(min_popup_height) + """, 83 | maxheight: 40, 84 | minwidth: 120, 85 | maxwidth: 120 86 | } 87 | )""" 88 | ) 89 | EOF 90 | redraw 91 | else 92 | let s:target_candidates = '' 93 | echohl WarningMsg | echomsg 'Something went wrong with disassembly service. See Cxxd server log for more details!' | echohl None 94 | endif 95 | endfunction 96 | 97 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 98 | " Function: cxxd#services#disassembly#select_target_from_pick_target_callback() 99 | " Description: Popup menu callback from cxxd#services#disassembly#pick_target_callback. 100 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 101 | function! cxxd#services#disassembly#select_target_from_pick_target_callback(id, target_entry) 102 | if a:target_entry < 1 103 | let s:target_selected_idx = -1 104 | return 105 | endif 106 | 107 | let s:target_selected_idx = a:target_entry - 1 108 | echomsg 'Target selected ' . s:target_selected_idx 109 | python3 << EOF 110 | import vim 111 | with open(vim.eval('s:target_candidates'), 'r') as f: 112 | candidates = f.readlines()[0].split(',') 113 | selected = candidates[int(vim.eval('s:target_selected_idx'))] 114 | vim.command('let s:target_selected=' + selected) 115 | EOF 116 | echomsg 'Target selected ' . s:target_selected 117 | endfunction 118 | 119 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 120 | " Function: cxxd#services#disassembly#pick_symbol() 121 | " Description: Retrives the list of symbols which match to the symbol located at (filename, line, column) 122 | " and in previously selected target. 123 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 124 | function! cxxd#services#disassembly#pick_symbol(filename, line, column) 125 | if g:cxxd_disassembly['started'] && g:cxxd_disassembly['enabled'] && s:target_selected != '' 126 | python3 cxxd.api.disassembly_list_symbol_candidates(server_handle, vim.eval('s:target_selected'), vim.eval('a:filename'), vim.eval('a:line'), vim.eval('a:column')) 127 | endif 128 | endfunction 129 | 130 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 131 | " Function: cxxd#services#disassembly#pick_symbol_callback() 132 | " Description: Callback from cxxd#services#disassembly#pick_symbol. 133 | " This is where we present the list of symbols in a popup menu 134 | " which user can use to select an entry (symbol of interest). 135 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 136 | function! cxxd#services#disassembly#pick_symbol_callback(status, symbol_candidates, nr_of_symbols) 137 | if a:status == 1 138 | let s:symbol_candidates = a:symbol_candidates 139 | if a:nr_of_symbols > 0 140 | python3 << EOF 141 | import vim 142 | min_popup_height = 10 if int(vim.eval('a:nr_of_symbols')) > 10 else int(vim.eval('a:nr_of_symbols')) 143 | with open(vim.eval('a:symbol_candidates'), 'r') as f: 144 | vim.eval("popup_menu([" + f.read() + """], 145 | #{ title: \'Select the symbol\', 146 | callback: 'cxxd#services#disassembly#select_symbol_from_pick_symbol_callback', 147 | highlight: 'Question', 148 | filter: 's:popup_filter', 149 | minheight: """ + str(min_popup_height) + """, 150 | maxheight: 40, 151 | minwidth: 120, 152 | maxwidth: 240 153 | } 154 | )""" 155 | ) 156 | EOF 157 | else 158 | echohl WarningMsg | echomsg 'No symbol candidates found. Symbol is most likely inlined or not visible from current translation unit. Try with another one!' | echohl None 159 | endif 160 | else 161 | let s:symbol_candidates = '' 162 | echohl WarningMsg | echomsg 'Something went wrong with disassembly service. See Cxxd server log for more details!' | echohl None 163 | endif 164 | redraw 165 | endfunction 166 | 167 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 168 | " Function: cxxd#services#disassembly#select_symbol_from_pick_symbol_callback() 169 | " Description: Popup menu callback from cxxd#services#disassembly#pick_symbol_callback. 170 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 171 | function! cxxd#services#disassembly#select_symbol_from_pick_symbol_callback(id, symbol_entry) 172 | if a:symbol_entry < 1 173 | let s:symbol_selected_idx = -1 174 | return 175 | endif 176 | 177 | let s:symbol_selected_idx = a:symbol_entry - 1 178 | echomsg 'Symbol selected ' . s:symbol_selected_idx 179 | call cxxd#services#disassembly#run() 180 | endfunction 181 | 182 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 183 | " Function: cxxd#services#disassembly#run() 184 | " Description: Disassembles the selected target and jumps to the selected symbol. 185 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 186 | function! cxxd#services#disassembly#run() 187 | if g:cxxd_disassembly['started'] && g:cxxd_disassembly['enabled'] && s:target_selected != '' && s:symbol_selected_idx != -1 188 | python3 cxxd.api.disassembly_run(server_handle, vim.eval('s:target_selected'), vim.eval('s:symbol_selected_idx')) 189 | endif 190 | endfunction 191 | 192 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 193 | " Function: cxxd#services#disassembly#run_callback() 194 | " Description: Callback from cxxd#services#disassembly#run. Displays the disassembled binary and jumps to the selected symbol. 195 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 196 | function! cxxd#services#disassembly#run_callback(status, disassembly_output, address, offset) 197 | if a:status == v:true 198 | if bufloaded(a:disassembly_output) == 0 199 | execute('vs' . a:disassembly_output) 200 | else 201 | let l:bufnr = bufnr(a:disassembly_output) 202 | let l:winnr = win_findbuf(l:bufnr) 203 | call win_gotoid(l:winnr[0]) 204 | call cursor(1, 1) 205 | " It's possible that we switched between different targets in the 206 | " meantime so we have to force Vim to reload the contents 207 | execute('e') 208 | endif 209 | execute('set ft=gas') 210 | execute('setlocal readonly') 211 | execute('setlocal nomodifiable') 212 | call search(a:address . ':') 213 | else 214 | echohl WarningMsg | echomsg 'Something went wrong with disassembly service. See Cxxd server log for more details!' | echohl None 215 | endif 216 | endfunction 217 | 218 | function! cxxd#services#disassembly#asm_instruction_info() 219 | let s:asm_winnr = v:beval_winnr 220 | let s:asm_line = v:beval_lnum 221 | let s:asm_col = v:beval_col 222 | if v:beval_text != '' 223 | python3 cxxd.api.disassembly_asm_doc( 224 | \ server_handle, 225 | \ vim.eval('v:beval_text') 226 | \ ) 227 | endif 228 | return '' 229 | endfunction 230 | 231 | function! cxxd#services#disassembly#asm_instruction_info_callback(status, tooltip, description, url) 232 | if a:status == v:true 233 | let pos = screenpos(s:asm_winnr, s:asm_line, s:asm_col) 234 | let l:descr = ["== Short description ==", "", a:tooltip, "", "Link: " . a:url, "", "== More details ==", "", a:description] 235 | call popup_create(l:descr, #{ 236 | \ line: pos.row, 237 | \ col: pos.col, 238 | \ minwidth: 80, 239 | \ maxwidth: 80, 240 | \ minheight: 2, 241 | \ maxheight: &lines - 1, 242 | \ border: [], 243 | \ padding: [], 244 | \ mapping: 0, 245 | \ scrollbar: 1, 246 | \ moved: 'WORD', 247 | \ mousemoved: 'WORD', 248 | \ drag: 1, 249 | \ highlight: 'Notification', 250 | \}) 251 | redraw 252 | else 253 | echohl WarningMsg | echomsg 'Something went wrong with disassembly service. See Cxxd server log for more details!' | echohl None 254 | endif 255 | endfunction 256 | 257 | function s:popup_filter(winid, key) abort 258 | if a:key ==# "\" 259 | call win_execute(a:winid, "normal! \") 260 | return v:true 261 | elseif a:key ==# "\" 262 | call win_execute(a:winid, "normal! \") 263 | return v:true 264 | elseif a:key ==# "\" || a:key ==# "\" 265 | call win_execute(a:winid, "normal! \") 266 | return v:true 267 | elseif a:key ==# "\" || a:key ==# "\" 268 | call win_execute(a:winid, "normal! \") 269 | return v:true 270 | elseif a:key ==# "\" 271 | call win_execute(a:winid, "normal! \") 272 | return v:true 273 | elseif a:key ==# "\" 274 | call win_execute(a:winid, "normal! \") 275 | return v:true 276 | elseif a:key ==# "\" 277 | call win_execute(a:winid, "normal! G") 278 | return v:true 279 | elseif a:key ==# "\" 280 | call win_execute(a:winid, "normal! gg") 281 | return v:true 282 | elseif a:key ==# 'q' 283 | call popup_close(a:winid) 284 | return v:true 285 | endif 286 | return popup_filter_menu(a:winid, a:key) 287 | endfunction 288 | -------------------------------------------------------------------------------- /plugin/cxxd/services/project_builder.vim: -------------------------------------------------------------------------------- 1 | " Variable holding a path to the file which will be containing build output 2 | let s:cxxd_project_builder_output_build_file = '' 3 | " Variable that keeps the buffer number of running terminal 4 | let s:terminal_buf_id = 0 5 | 6 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 7 | " Function: services#project_builder#start() 8 | " Description: Starts the project builder background service. 9 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 10 | function! cxxd#services#project_builder#start() 11 | python3 cxxd.api.project_builder_start(server_handle) 12 | endfunction 13 | 14 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 15 | " Function: cxxd#services#project_builder#start_callback() 16 | " Description: Callback from services#project_builder#start. 17 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 18 | function! cxxd#services#project_builder#start_callback(status, output_build_file) 19 | if a:status == v:true 20 | let g:cxxd_project_builder['started'] = 1 21 | let s:cxxd_project_builder_output_build_file = a:output_build_file 22 | else 23 | echohl WarningMsg | echomsg 'Something went wrong with project-builder service start-up. See Cxxd server log for more details!' | echohl None 24 | endif 25 | endfunction 26 | 27 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 28 | " Function: cxxd#services#project_builder#stop() 29 | " Description: Stops the project builder background service. 30 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 31 | function! cxxd#services#project_builder#stop(subscribe_for_shutdown_callback) 32 | python3 cxxd.api.project_builder_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 33 | endfunction 34 | 35 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 36 | " Function: cxxd#services#project_builder#stop_callback() 37 | " Description: Callback from services#project_builder#stop. 38 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 39 | function! cxxd#services#project_builder#stop_callback(status) 40 | if a:status == v:true 41 | let g:cxxd_project_builder['started'] = 0 42 | let s:cxxd_project_builder_output_build_file = '' 43 | else 44 | echohl WarningMsg | echomsg 'Something went wrong with project-builder service shut-down. See Cxxd server log for more details!' | echohl None 45 | endif 46 | endfunction 47 | 48 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 49 | " Function: cxxd#services#project_builder#run() 50 | " Description: Triggers the build for current project. 51 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 52 | function! cxxd#services#project_builder#run_custom(build_command, ...) 53 | if g:cxxd_project_builder['started'] && g:cxxd_project_builder['enabled'] 54 | let l:additional_args = '' 55 | if a:0 != 0 56 | let l:additional_args = a:1 57 | let i = 2 58 | while i <= a:0 59 | execute "let l:additional_args = l:additional_args . \" \" . a:" . i 60 | let i = i + 1 61 | endwhile 62 | endif 63 | call setqflist([]) 64 | python3 cxxd.api.project_builder_request_build_custom(server_handle, vim.eval('a:build_command') + ' ' + vim.eval('l:additional_args')) 65 | endif 66 | endfunction 67 | 68 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 69 | " Function: cxxd#services#project_builder#run() 70 | " Description: Triggers the build for current project but auto-detects the 71 | " build command from cxxd config file. 72 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 73 | function! cxxd#services#project_builder#run_target() 74 | if g:cxxd_project_builder['started'] && g:cxxd_project_builder['enabled'] 75 | call setqflist(getqflist(), 'f') 76 | python3 cxxd.api.project_builder_request_build_target(server_handle) 77 | let s:buf_nr = bufnr('build_log', 1) 78 | let s:log_job = job_start('tail -f ' . s:cxxd_project_builder_output_build_file, {'out_io': 'buffer', 'out_buf': s:buf_nr}) 79 | sbuf build_log 80 | wincmd J | below 81 | endif 82 | endfunction 83 | 84 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 85 | " Function: cxxd#services#project_builder#run_callback() 86 | " Description: Callback from services#project_builder#run. 87 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 88 | function! cxxd#services#project_builder#run_callback(status, duration, build_process_exit_code, build_output) 89 | echomsg 'Build process took ' . a:duration . ' with exit code ' . a:build_process_exit_code 90 | call job_stop(s:log_job) 91 | execute('bdelete! ' . s:buf_nr) 92 | execute('cgetfile ' . a:build_output) 93 | execute('copen') 94 | redraw 95 | endfunction 96 | 97 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#source_code_model#start() 3 | " Description: Starts the source code model background service. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#source_code_model#start() 6 | python3 cxxd.api.source_code_model_start(server_handle) 7 | endfunction 8 | 9 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 10 | " Function: cxxd#services#source_code_model#start_callback() 11 | " Description: Callback from cxxd#services#source_code_model#start. 12 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 13 | function! cxxd#services#source_code_model#start_callback(status) 14 | if a:status == v:true 15 | let g:cxxd_src_code_model['started'] = 1 16 | call cxxd#services#source_code_model#indexer#run_on_directory() 17 | else 18 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model service start-up. See Cxxd server log for more details!' | echohl None 19 | endif 20 | endfunction 21 | 22 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 23 | " Function: cxxd#services#source_code_model#stop() 24 | " Description: Stops the source code model background service. 25 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 26 | function! cxxd#services#source_code_model#stop(subscribe_for_shutdown_callback) 27 | python3 cxxd.api.source_code_model_stop(server_handle, vim.eval('a:subscribe_for_shutdown_callback')) 28 | endfunction 29 | 30 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 31 | " Function: cxxd#services#source_code_model#stop_callback() 32 | " Description: Callback from cxxd#services#source_code_model#stop. 33 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 34 | function! cxxd#services#source_code_model#stop_callback(status) 35 | if a:status == v:true 36 | let g:cxxd_src_code_model['started'] = 0 37 | else 38 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model service shut-down. See Cxxd server log for more details!' | echohl None 39 | endif 40 | endfunction 41 | 42 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model/diagnostics.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#source_code_model#diagnostics#run() 3 | " Description: Triggers the source code diagnostics for current buffer. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#source_code_model#diagnostics#run(filename) 6 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['diagnostics']['enabled'] 7 | " If buffer contents are modified but not saved, we need to serialize contents of the current buffer into temporary file. 8 | let l:contents_filename = cxxd#utils#pick_content_filename(a:filename) 9 | if cxxd#utils#is_more_modifications_done(winnr()) 10 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 11 | endif 12 | 13 | let l:winnr = winnr() 14 | if getloclist(l:winnr) == [] 15 | python3 cxxd.api.source_code_model_diagnostics_request(server_handle, vim.eval('a:filename'), vim.eval('l:contents_filename')) 16 | elseif getloclist(l:winnr)[0].bufnr != winbufnr(l:winnr) 17 | python3 cxxd.api.source_code_model_diagnostics_request(server_handle, vim.eval('a:filename'), vim.eval('l:contents_filename')) 18 | elseif cxxd#utils#is_more_modifications_done(l:winnr) 19 | python3 cxxd.api.source_code_model_diagnostics_request(server_handle, vim.eval('a:filename'), vim.eval('l:contents_filename')) 20 | endif 21 | endif 22 | endfunction 23 | 24 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 25 | " Function: cxxd#services#source_code_model#diagnostics#run_callback() 26 | " Description: Populates the quickfix window with source code diagnostics. 27 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 28 | function! cxxd#services#source_code_model#diagnostics#run_callback(status, diagnostics) 29 | let l:winnr = winnr() 30 | call setloclist(l:winnr, [{'bufnr' : winbufnr(l:winnr), 'text' : 'Clang diagnostics'}], 'r') 31 | if a:status == v:true 32 | call setloclist(l:winnr, a:diagnostics, 'a') 33 | redraw 34 | else 35 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (diagnostics) service. See Cxxd server log for more details!' | echohl None 36 | endif 37 | endfunction 38 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model/go_to_definition.vim: -------------------------------------------------------------------------------- 1 | let s:show_definition_in_preview_window = v:false 2 | 3 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 4 | " Function: cxxd#services#source_code_model#go_to_definition#run() 5 | " Description: Jumps to the definition of a symbol under the cursor. 6 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 7 | function! cxxd#services#source_code_model#go_to_definition#run(filename, line, col, show_definition_in_preview_window) 8 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['go_to_definition']['enabled'] 9 | let s:show_definition_in_preview_window = a:show_definition_in_preview_window 10 | " If buffer contents are modified but not saved, we need to serialize contents of the current buffer into temporary file. 11 | let l:contents_filename = cxxd#utils#pick_content_filename(a:filename) 12 | if cxxd#utils#is_more_modifications_done(winnr()) 13 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 14 | endif 15 | python3 cxxd.api.source_code_model_go_to_definition_request( 16 | \ server_handle, 17 | \ vim.eval('a:filename'), 18 | \ vim.eval('l:contents_filename'), 19 | \ vim.eval('a:line'), 20 | \ vim.eval('a:col') 21 | \ ) 22 | endif 23 | endfunction 24 | 25 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 26 | " Function: cxxd#services#source_code_model#go_to_definition#run_callback() 27 | " Description: Jumps to the definition found. 28 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 29 | function! cxxd#services#source_code_model#go_to_definition#run_callback(status, filename, line, column) 30 | if a:status == v:true 31 | if a:filename != '' 32 | if s:show_definition_in_preview_window 33 | call cxxd#utils#preview_open(a:filename, a:line, a:column) 34 | else 35 | if expand('%p') != a:filename 36 | execute('edit ' . a:filename) 37 | endif 38 | call cursor(a:line, a:column) 39 | endif 40 | else 41 | echohl WarningMsg | echom 'No definition found!' | echohl None 42 | endif 43 | else 44 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (go-to-definition) service. See Cxxd server log for more details!' | echohl None 45 | endif 46 | endfunction 47 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model/go_to_include.vim: -------------------------------------------------------------------------------- 1 | let s:show_include_in_preview_window = v:false 2 | 3 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 4 | " Function: cxxd#services#source_code_model#go_to_include#run() 5 | " Description: Fetches the filename which include directive corresponds to on the given (current) line. 6 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 7 | function! cxxd#services#source_code_model#go_to_include#run(filename, line, show_include_in_preview_window) 8 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['go_to_include']['enabled'] 9 | let s:show_include_in_preview_window = a:show_include_in_preview_window 10 | " If buffer contents are modified but not saved, we need to serialize contents of the current buffer into temporary file. 11 | let l:contents_filename = cxxd#utils#pick_content_filename(a:filename) 12 | if cxxd#utils#is_more_modifications_done(winnr()) 13 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 14 | endif 15 | python3 cxxd.api.source_code_model_go_to_include_request( 16 | \ server_handle, 17 | \ vim.eval('a:filename'), 18 | \ vim.eval('l:contents_filename'), 19 | \ vim.eval('a:line') 20 | \ ) 21 | endif 22 | endfunction 23 | 24 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 25 | " Function: cxxd#services#source_code_model#go_to_include#run_callback() 26 | " Description: Opens the filename which corresponds to the include directive. 27 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 28 | function! cxxd#services#source_code_model#go_to_include#run_callback(status, filename) 29 | if a:status == v:true 30 | if a:filename != '' 31 | if s:show_include_in_preview_window 32 | call cxxd#utils#preview_open(a:filename, 1, 1) 33 | else 34 | execute('edit ' . a:filename) 35 | endif 36 | else 37 | echohl WarningMsg | echom 'No corresponding include file found!' | echohl None 38 | endif 39 | else 40 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (go-to-include) service. See Cxxd server log for more details!' | echohl None 41 | endif 42 | endfunction 43 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model/indexer.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#source_code_model#indexer#run_on_single_file() 3 | " Description: Runs indexer on a single file. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#source_code_model#indexer#run_on_single_file(filename) 6 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 7 | python3 cxxd.api.source_code_model_indexer_run_on_single_file_request( 8 | \ server_handle, 9 | \ vim.eval('a:filename') 10 | \ ) 11 | endif 12 | endfunction 13 | 14 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 15 | " Function: cxxd#services#source_code_model#indexer#run_on_single_file_callback() 16 | " Description: Running indexer on a single file completed. 17 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 18 | function! cxxd#services#source_code_model#indexer#run_on_single_file_callback(status) 19 | if a:status != v:true 20 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (indexer-run-on-single-file) service. See Cxxd server log for more details!' | echohl None 21 | endif 22 | endfunction 23 | 24 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 25 | " Function: cxxd#services#source_code_model#indexer#run_on_directory() 26 | " Description: Runs indexer on a whole directory. 27 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 28 | function! cxxd#services#source_code_model#indexer#run_on_directory() 29 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 30 | echomsg 'Indexing started ... It may take a while if it is run for the first time.' 31 | python3 cxxd.api.source_code_model_indexer_run_on_directory_request(server_handle) 32 | endif 33 | endfunction 34 | 35 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 36 | " Function: cxxd#services#source_code_model#indexer#run_on_directory_callback() 37 | " Description: Running indexer on a directory completed. 38 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 39 | function! cxxd#services#source_code_model#indexer#run_on_directory_callback(status) 40 | if a:status == v:true 41 | echomsg 'Indexing successfully completed.' 42 | call cxxd#services#source_code_model#indexer#fetch_all_diagnostics( 43 | \ g:cxxd_fetch_all_diagnostics_sorting_strategies['severity_desc'] 44 | \ ) 45 | else 46 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (indexer-run-on-directory) service. See Cxxd server log for more details!' | echohl None 47 | endif 48 | endfunction 49 | 50 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 51 | " Function: cxxd#services#source_code_model#indexer#run_on_directory_callback() 52 | " Description: Drops index for given file from the indexer. 53 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 54 | function! cxxd#services#source_code_model#indexer#drop_single_file(filename) 55 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 56 | python3 cxxd.api.source_code_model_indexer_drop_single_file_request(server_handle, vim.eval('a:filename')) 57 | endif 58 | endfunction 59 | 60 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 61 | " Function: cxxd#services#source_code_model#indexer#drop_single_file_callback() 62 | " Description: Dropping single file from indexing results completed. 63 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 64 | function! cxxd#services#source_code_model#indexer#drop_single_file_callback(status) 65 | if a:status != v:true 66 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (indexer-drop-single-file) service. See Cxxd server log for more details!' | echohl None 67 | endif 68 | endfunction 69 | 70 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 71 | " Function: cxxd#services#source_code_model#indexer#drop_all() 72 | " Description: Drops all of the indices from the indexer. 73 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 74 | function! cxxd#services#source_code_model#indexer#drop_all() 75 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 76 | python3 cxxd.api.source_code_model_indexer_drop_all_request(server_handle, True) 77 | endif 78 | endfunction 79 | 80 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 81 | " Function: cxxd#services#source_code_model#indexer#drop_all() 82 | " Description: Dropping all indices from indexing results completed. 83 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 84 | function! cxxd#services#source_code_model#indexer#drop_all_callback(status) 85 | if a:status == v:true 86 | echomsg 'Indexing symbol database successfully dropped ...' 87 | else 88 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (indexer-drop-all) service. See Cxxd server log for more details!' | echohl None 89 | endif 90 | endfunction 91 | 92 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 93 | " Function: cxxd#services#source_code_model#indexer#drop_all_and_run_on_directory() 94 | " Description: Drops the index database and runs indexer again (aka reindexing operation) 95 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 96 | function! cxxd#services#source_code_model#indexer#drop_all_and_run_on_directory() 97 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 98 | echomsg 'About to drop symbol database and re-run the source code indexer ...' 99 | python3 cxxd.api.source_code_model_indexer_drop_all_and_run_on_directory_request(server_handle) 100 | endif 101 | endfunction 102 | 103 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 104 | " Function: cxxd#services#source_code_model#indexer#find_all_references() 105 | " Description: Finds project-wide references of a symbol under the cursor. 106 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 107 | function! cxxd#services#source_code_model#indexer#find_all_references(filename, line, col) 108 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 109 | " If buffer contents are modified but not saved, we need to serialize contents of the current buffer into temporary file. 110 | let l:contents_filename = cxxd#utils#pick_content_filename(a:filename) 111 | if cxxd#utils#is_more_modifications_done(winnr()) 112 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 113 | endif 114 | python3 cxxd.api.source_code_model_indexer_find_all_references_request( 115 | \ server_handle, 116 | \ vim.eval('l:contents_filename'), 117 | \ vim.eval('a:line'), 118 | \ vim.eval('a:col') 119 | \ ) 120 | endif 121 | endfunction 122 | 123 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 124 | " Function: cxxd#services#source_code_model#indexer#find_all_references_callback() 125 | " Description: Found references. 126 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 127 | function! cxxd#services#source_code_model#indexer#find_all_references_callback(status, references) 128 | if a:status == v:true 129 | python3 << EOF 130 | import vim 131 | with open(vim.eval('a:references'), 'r') as f: 132 | vim.eval("setqflist([" + f.read() + "], 'r')") 133 | EOF 134 | execute('copen') 135 | redraw 136 | else 137 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (indexer-find-all-references) service. See Cxxd server log for more details!' | echohl None 138 | endif 139 | endfunction 140 | 141 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 142 | " Function: cxxd#services#source_code_model#indexer#fetch_all_diagnostics() 143 | " Description: Fetches all of the source code issues/diagnostics. 144 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 145 | function! cxxd#services#source_code_model#indexer#fetch_all_diagnostics(fetch_sorting_strategy) 146 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['indexer']['enabled'] 147 | python3 cxxd.api.source_code_model_indexer_fetch_all_diagnostics_request( 148 | \ server_handle, 149 | \ vim.eval("a:fetch_sorting_strategy") 150 | \ ) 151 | endif 152 | endfunction 153 | 154 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 155 | " Function: cxxd#services#source_code_model#indexer#fetch_all_diagnostics_callback() 156 | " Description: Diagnostics. 157 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 158 | function! cxxd#services#source_code_model#indexer#fetch_all_diagnostics_callback(status, diagnostics) 159 | if a:status == v:true 160 | if len(a:diagnostics) 161 | echohl WarningMsg | echomsg 'Some issues during source code indexing were found. For better experience, please inspect those in QuickFix window.' | echohl None 162 | else 163 | echohl MoreMsg | echomsg 'Kewl. No issues were found with the code.' | echohl None 164 | endif 165 | python3 << EOF 166 | import vim 167 | with open(vim.eval('a:diagnostics'), 'r') as f: 168 | vim.eval("setqflist([" + f.read() + "], 'r')") 169 | EOF 170 | execute('copen') 171 | redraw 172 | else 173 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (indexer-fetch-all-diagnostics) service. See Cxxd server log for more details!' | echohl None 174 | endif 175 | endfunction 176 | 177 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model/semantic_syntax_highlight.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#source_code_model#semantic_syntax_highlight#run() 3 | " Description: Triggers the source code highlighting for current buffer. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#source_code_model#semantic_syntax_highlight#run(filename) 6 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['semantic_syntax_highlight']['enabled'] 7 | " If buffer contents are modified but not saved, we need to serialize contents of the current buffer into temporary file. 8 | let l:contents_filename = cxxd#utils#pick_content_filename(a:filename) 9 | if cxxd#utils#is_more_modifications_done(winnr()) 10 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 11 | endif 12 | 13 | " We don't want to fire semantic syntax highlighting request on each 14 | " CursorHold(I) event but only when viewport has been actually changed or 15 | " if there were some modifications being done. 16 | let l:current_visible_line_begin = line('w0') 17 | let l:current_visible_line_end = line('w$') 18 | if cxxd#utils#is_more_modifications_done(winnr()) || cxxd#utils#is_viewport_changed(winnr()) 19 | python3 cxxd.api.source_code_model_semantic_syntax_highlight_request( 20 | \ server_handle, vim.eval('a:filename'), vim.eval('l:contents_filename'), vim.eval('l:current_visible_line_begin'), vim.eval('l:current_visible_line_end') 21 | \ ) 22 | endif 23 | endif 24 | endfunction 25 | 26 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 27 | " Function: cxxd#services#source_code_model#semantic_syntax_highlight#run_callback() 28 | " Description: Apply the results of source code highlighting for given filename. 29 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 30 | function! cxxd#services#source_code_model#semantic_syntax_highlight#run_callback(status, filename, syntax_file) 31 | if a:status == v:true 32 | let l:current_buffer = expand('%:p') 33 | if l:current_buffer == a:filename 34 | " Clear all previously added matches 35 | call clearmatches() 36 | 37 | " Apply the syntax highlighting rules 38 | execute('source ' . a:syntax_file) 39 | 40 | " Following command is a quick hack to apply the new syntax for 41 | " the given buffer. I haven't found any other more viable way to do it 42 | " while keeping it fast & low on resources, 43 | execute(':redrawstatus') 44 | endif 45 | else 46 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (semantic-syntax-highlighting) service. See Cxxd server log for more details!' | echohl None 47 | endif 48 | endfunction 49 | 50 | -------------------------------------------------------------------------------- /plugin/cxxd/services/source_code_model/type_deduction.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#services#source_code_model#type_deduction#run() 3 | " Description: Extracts information about the underlying type (on mouse-hover). 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#services#source_code_model#type_deduction#run() 6 | if g:cxxd_src_code_model['started'] && g:cxxd_src_code_model['services']['type_deduction']['enabled'] 7 | " Execute requests only on non-special, ordinary buffers. I.e. ignore NERD_Tree, Tagbar, quickfix and alike. 8 | " In case of non-ordinary buffers, buffer may not even exist on a disk and triggering the service does not 9 | " any make sense then. 10 | if getbufvar(v:beval_bufnr, "&buftype") == '' 11 | let l:current_buffer = fnamemodify(bufname(v:beval_bufnr), ':p') 12 | 13 | " If buffer contents are modified but not saved, we need to serialize contents of the current buffer into temporary file. 14 | let l:contents_filename = cxxd#utils#pick_content_filename(l:current_buffer) 15 | if cxxd#utils#is_more_modifications_done(winnr('#')) 16 | call cxxd#utils#serialize_current_buffer_contents(l:contents_filename) 17 | endif 18 | python3 cxxd.api.source_code_model_type_deduction_request( 19 | \ server_handle, 20 | \ vim.eval('l:current_buffer'), 21 | \ vim.eval('l:contents_filename'), 22 | \ vim.eval('v:beval_lnum'), 23 | \ vim.eval('v:beval_col') 24 | \ ) 25 | endif 26 | endif 27 | return '' 28 | endfunction 29 | 30 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 31 | " Function: cxxd#services#source_code_model#type_deduction#run_callback() 32 | " Description: Display extracted information about the type in a balloon. 33 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 34 | function! cxxd#services#source_code_model#type_deduction#run_callback(status, deducted_type) 35 | if a:status == v:true 36 | if exists('*balloon_show') 37 | if a:deducted_type != '' 38 | call balloon_show(a:deducted_type) 39 | endif 40 | else 41 | echo a:deducted_type 42 | endif 43 | else 44 | echohl WarningMsg | echomsg 'Something went wrong with source-code-model (type-deduction) service. See Cxxd server log for more details!' | echohl None 45 | endif 46 | endfunction 47 | -------------------------------------------------------------------------------- /plugin/cxxd/utils.vim: -------------------------------------------------------------------------------- 1 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | " Function: cxxd#utils#serialize_current_buffer_contents 3 | " Description: Function which serializes current buffer contents to the given filename. 4 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | function! cxxd#utils#serialize_current_buffer_contents(to_filename) 6 | python3 << EOF 7 | import vim 8 | with open(vim.eval('a:to_filename'), "w") as f: 9 | f.writelines(line + '\n' for line in vim.current.buffer) 10 | EOF 11 | endfunction 12 | 13 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 14 | " Function: cxxd#utils#pick_content_filename 15 | " Description: Function which short-circuits the input to output if input filename has not been modified. 16 | " Otherwise, it returns a new output filename whose name is generated out of the input filename base. 17 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 18 | function! cxxd#utils#pick_content_filename(filename) 19 | if getbufvar(a:filename, '&modified') 20 | return '/tmp/tmp_' . fnamemodify(a:filename, ':p:t') 21 | else 22 | return a:filename 23 | endif 24 | endfunction 25 | 26 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 27 | " Function: cxxd#utils#init_window_specific_vars 28 | " Description: Function which instantiates and initializes window-specific variables which we use to emulate 29 | " some inexisting events in Vim (e.g. 'ViewportChanged'). 30 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 31 | function! cxxd#utils#init_window_specific_vars() 32 | if !exists('w:text_changed') | let w:text_changed = v:false | endif 33 | if !exists('w:text_changed_i') | let w:text_changed_i = v:false | endif 34 | if !exists('w:previous_num_of_changes') | let w:previous_num_of_changes = 0 | endif 35 | if !exists('w:more_modifications_done') | let w:more_modifications_done = v:false | endif 36 | if !exists('w:previous_visible_line_begin') | let w:previous_visible_line_begin = 0 | endif 37 | if !exists('w:previous_visible_line_end') | let w:previous_visible_line_end = 0 | endif 38 | if !exists('w:viewport_changed') | let w:viewport_changed = v:false | endif 39 | endfunction 40 | 41 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 42 | " Function: cxxd#utils#is_more_modifications_done 43 | " Description: Check if more modifications has been done in given window. 44 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 45 | function! cxxd#utils#is_more_modifications_done(winnr) 46 | return getwinvar(a:winnr, 'text_changed') && getwinvar(a:winnr, 'more_modifications_done') 47 | endfunction 48 | 49 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 50 | " Function: cxxd#utils#is_viewport_changed 51 | " Description: Check if viewport has been changed for given window. 52 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 53 | function! cxxd#utils#is_viewport_changed(winnr) 54 | return getwinvar(a:winnr, 'viewport_changed') 55 | endfunction 56 | 57 | function! cxxd#utils#modifications_handler_i(winnr) 58 | call setwinvar(a:winnr, 'text_changed', v:true) 59 | call setwinvar(a:winnr, 'text_changed_i', v:true) 60 | endfunction 61 | 62 | function! cxxd#utils#modifications_handler_p(winnr) 63 | if getwinvar(a:winnr, 'text_changed_i') 64 | call setwinvar(a:winnr, 'text_changed', v:false) 65 | call setwinvar(a:winnr, 'text_changed_i', v:false) 66 | else 67 | call setwinvar(a:winnr, 'text_changed', v:true) 68 | endif 69 | endfunction 70 | 71 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 72 | " Function: cxxd#utils#modifications_handler 73 | " Description: Handler which checks if more modifications has been done in given window and accordingly set relevant variables. 74 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 75 | function! cxxd#utils#modifications_handler(winnr) 76 | if getbufinfo(winbufnr(a:winnr))[0].changed 77 | let l:previous_num_of_changes = getwinvar(a:winnr, 'previous_num_of_changes') 78 | let l:num_of_changes = getbufinfo(winbufnr(a:winnr))[0].changedtick 79 | call setwinvar(a:winnr, 'previous_num_of_changes', l:num_of_changes) 80 | call setwinvar(a:winnr, 'more_modifications_done', l:num_of_changes != l:previous_num_of_changes) 81 | else 82 | call setwinvar(a:winnr, 'more_modifications_done', v:false) 83 | endif 84 | endfunction 85 | 86 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 87 | " Function: cxxd#utils#viewport_handler 88 | " Description: Handler which checks if viewport has been changed for given window and accordingly set relevant variables. 89 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 90 | function! cxxd#utils#viewport_handler(winnr, current_visible_line_begin, current_visible_line_end) 91 | let l:previous_visible_line_begin = getwinvar(a:winnr, 'previous_visible_line_begin') 92 | let l:previous_visible_line_end = getwinvar(a:winnr, 'previous_visible_line_end') 93 | 94 | " Because we are missing a proper event support in Vim, we are using a 'CursorHold(I)' event context 95 | " to emulate 'ViewportChanged' event. We just need to filter out unnecessary 'CursorHold' events ... 96 | " 1. CursorHold(I) events can be triggered by moving the cursor horizontally 97 | " * In which case we will report back that viewport 98 | " hasn't been changed 99 | " 2. CursorHold(I) events can be triggered by moving cursor vertically 100 | " but not enough to change the viewport (i.e. moving cursor across 101 | " the lines but without changing the first and last line visible 102 | " in the given window) 103 | " * In which case we will still report back that viewport 104 | " hasn't been changed 105 | " 3. CursorHold(I) events can be triggered by moving cursor vertically 106 | " but this time enough to impact the viewport (i.e. move 107 | " cursor upwards when we are at the top of the viewport or 108 | " move cursor downwards when we are the bottom of the 109 | " viewport) 110 | " * In which case we will report back that viewport 111 | " has been changed 112 | let l:viewport_changed = v:false 113 | if a:current_visible_line_begin != l:previous_visible_line_begin 114 | call setwinvar(a:winnr, 'previous_visible_line_begin', a:current_visible_line_begin) 115 | let l:viewport_changed = v:true 116 | endif 117 | if a:current_visible_line_end != l:previous_visible_line_end 118 | call setwinvar(a:winnr, 'previous_visible_line_end', a:current_visible_line_end) 119 | let l:viewport_changed = v:true 120 | endif 121 | call setwinvar(a:winnr, 'viewport_changed', l:viewport_changed) 122 | endfunction 123 | 124 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 125 | " Function: cxxd#utils#last_occurence_of_non_identifier 126 | " Description: Return the index of last occurence of non-identifier. E.g. ; or } 127 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 128 | function! cxxd#utils#last_occurence_of_non_identifier(str) 129 | let l:idx = -1 130 | python << EOF 131 | import vim 132 | def is_identifier(char): 133 | is_digit = char.isdigit() 134 | is_alpha = char.isalpha() 135 | is_underscore = char == '_' 136 | return is_digit or is_alpha or is_underscore 137 | 138 | string = vim.eval('a:str') 139 | vim.command('let l:idx = %s' % str(-1)) 140 | for idx, char in enumerate(string[::-1]): 141 | if not is_identifier(char): 142 | vim.command('let l:idx = %s' % str(idx)) 143 | break 144 | EOF 145 | return l:idx 146 | endfunction 147 | 148 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 149 | " Function: cxxd#utils#statement_finished 150 | " Description: Deduce whether the statement is finished or not. 151 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 152 | function! cxxd#utils#statement_finished(str) 153 | let l:last_char = a:str[len(a:str)-1] 154 | return l:last_char == ';' || l:last_char == '}' 155 | endfunction 156 | 157 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 158 | " Function: cxxd#utils#preview_open 159 | " Description: Open given filename at given (line, column) position in a pop-up floating window. 160 | " I scraped this impl somewhere from the web and tweaked a bit to accomodate my case 161 | " but can't remember exactly from where. Will give it credit if I do. 162 | " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 163 | function! cxxd#utils#preview_open(filename, line, column) 164 | let bufnr = bufadd(a:filename) 165 | let wininfo = getwininfo(win_getid())[0] 166 | let space_above = &lines - line('.') + 1 167 | let space_below = line('.') 168 | let lnum = a:line 169 | let firstline = a:line - s:preview_win_get('offset') < 1 ? 1 : a:line - s:preview_win_get('offset') 170 | let height = s:preview_win_get('height') 171 | 172 | let title = a:filename 173 | 174 | " Truncate long titles at beginning 175 | if len(title) > wininfo.width 176 | let title = '…' .. title[-(wininfo.width-4):] 177 | endif 178 | 179 | if space_above > height 180 | if space_above == height + 1 181 | let height = height - 1 182 | endif 183 | let opts = { 184 | \ 'line': 'cursor-1', 185 | \ 'pos': 'botleft' 186 | \ } 187 | elseif space_below >= height 188 | let opts = { 189 | \ 'line': 'cursor+1', 190 | \ 'pos': 'topleft' 191 | \ } 192 | elseif space_above > 5 193 | let height = space_above - 2 194 | let opts = { 195 | \ 'line': 'cursor', 196 | \ 'pos': 'botleft' 197 | \ } 198 | elseif space_below > 5 199 | let height = space_below - 2 200 | let opts = { 201 | \ 'line': 'cursor' 202 | \ 'pos': 'topleft' 203 | \ } 204 | elseif space_above <= 5 || space_below <= 5 205 | let opts = { 206 | \ 'line': &lines - &cmdheight, 207 | \ 'pos': 'botleft' 208 | \ } 209 | else 210 | echohl ErrorMsg 211 | echomsg 'Not enough space to display popup window.' 212 | echohl None 213 | return 214 | endif 215 | 216 | silent let winid = popup_create(bufnr, extend(opts, { 217 | \ 'col': wininfo.wincol, 218 | \ 'minheight': height, 219 | \ 'maxheight': height, 220 | \ 'minwidth': wininfo.width - 1, 221 | \ 'maxwidth': wininfo.width - 1, 222 | \ 'firstline': firstline, 223 | \ 'title': title, 224 | \ 'close': s:preview_win_get('mouseclick'), 225 | \ 'padding': [0,1,1,1], 226 | \ 'border': [1,0,0,0], 227 | \ 'borderchars': [' '], 228 | \ 'moved': 'any', 229 | \ 'mapping': v:false, 230 | \ 'filter': funcref('s:preview_win_popup_filter', [firstline]), 231 | \ 'filtermode': 'n', 232 | \ 'highlight': 'QfPreview', 233 | \ 'scrollbar': s:preview_win_get('scrollbar'), 234 | \ 'borderhighlight': ['QfPreviewTitle'], 235 | \ 'scrollbarhighlight': 'QfPreviewScrollbar', 236 | \ 'thumbhighlight': 'QfPreviewThumb', 237 | \ 'callback': {... -> !empty(s:preview_win_get('sign')) 238 | \ ? [sign_unplace('PopUpQfPreview'), sign_undefine('QfErrorLine')] 239 | \ : 0 240 | \ } 241 | \ }))) 242 | 243 | " Set firstline to zero to prevent jumps when calling win_execute() #4876 244 | call popup_setoptions(winid, {'firstline': 0}) 245 | call setwinvar(winid, '&number', !!s:preview_win_get('number')) 246 | 247 | if !empty(s:preview_win_get('sign')->get('text', '')) 248 | call setwinvar(winid, '&signcolumn', 'number') 249 | endif 250 | 251 | if !empty(s:preview_win_get('sign')) 252 | call sign_define('QfErrorLine', s:preview_win_get('sign')) 253 | call sign_place(0, 'PopUpQfPreview', 'QfErrorLine', bufnr, {'lnum': lnum}) 254 | endif 255 | 256 | return winid 257 | endfunction 258 | 259 | let s:preview_win_defaults = { 260 | \ 'height': 15, 261 | \ 'mouseclick': 'button', 262 | \ 'scrollbar': v:true, 263 | \ 'number': v:false, 264 | \ 'offset': 0, 265 | \ 'sign': {'linehl': 'CursorLine'}, 266 | \ 'scrollup': "\", 267 | \ 'scrolldown': "\", 268 | \ 'halfpageup': "\", 269 | \ 'halfpagedown': "\", 270 | \ 'fullpageup': "\", 271 | \ 'fullpagedown': "\", 272 | \ 'close': 'x' 273 | \ } 274 | 275 | let s:preview_win_get = {x -> get(b:, 'qfpreview', get(g:, 'qfpreview', {}))->get(x, s:preview_win_defaults[x])} 276 | 277 | function! s:preview_win_set_height(winid, step) abort 278 | let height = popup_getoptions(a:winid).minheight 279 | let newheight = height + a:step > 0 ? height + a:step : 1 280 | call popup_setoptions(a:winid, {'minheight': newheight, 'maxheight': newheight}) 281 | if !empty(s:preview_win_get('sign')->get('text', '')) 282 | call setwinvar(a:winid, '&signcolumn', 'number') 283 | endif 284 | endfunction 285 | 286 | function! s:preview_win_popup_filter(line, winid, key) abort 287 | if a:key ==# s:preview_win_get('scrollup') 288 | call win_execute(a:winid, "normal! \") 289 | elseif a:key ==# s:preview_win_get('scrolldown') 290 | call win_execute(a:winid, "normal! \") 291 | elseif a:key ==# s:preview_win_get('halfpageup') 292 | call win_execute(a:winid, "normal! \") 293 | elseif a:key ==# s:preview_win_get('halfpagedown') 294 | call win_execute(a:winid, "normal! \") 295 | elseif a:key ==# s:preview_win_get('fullpageup') 296 | call win_execute(a:winid, "normal! \") 297 | elseif a:key ==# s:preview_win_get('fullpagedown') 298 | call win_execute(a:winid, "normal! \") 299 | elseif a:key ==# s:preview_win_get('close') 300 | call popup_close(a:winid) 301 | elseif a:key ==# 'g' 302 | call win_execute(a:winid, 'normal! gg') 303 | elseif a:key ==# 'G' 304 | call win_execute(a:winid, 'normal! G') 305 | elseif a:key ==# '+' 306 | call s:preview_win_set_height(a:winid, 1) 307 | elseif a:key ==# '-' 308 | call s:preview_win_set_height(a:winid, -1) 309 | elseif a:key ==# 'r' 310 | call popup_setoptions(a:winid, {'firstline': a:line}) 311 | call popup_setoptions(a:winid, {'firstline': 0}) 312 | " Note: after popup_setoptions() 'signcolumn' needs to be reset again 313 | if !empty(s:preview_win_get('sign')->get('text', '')) 314 | call setwinvar(a:winid, '&signcolumn', 'number') 315 | endif 316 | else 317 | return v:false 318 | endif 319 | return v:true 320 | endfunction 321 | -------------------------------------------------------------------------------- /syntax/cpp/cxxd.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: C++ 3 | 4 | hi def link CxxdNamespace NamespaceTag 5 | hi def link CxxdNamespaceAlias NamespaceAliasTag 6 | hi def link CxxdClass ClassTag 7 | hi def link CxxdStructure StructureTag 8 | hi def link CxxdEnum EnumTag 9 | hi def link CxxdEnumValue EnumValueTag 10 | hi def link CxxdUnion UnionTag 11 | hi def link CxxdField FieldTag 12 | hi def link CxxdLocalVariable LocalVariableTag 13 | hi def link CxxdFunction FunctionTag 14 | hi def link CxxdMethod MethodTag 15 | hi def link CxxdFunctionParameter FunctionParameterTag 16 | hi def link CxxdTemplateTypeParameter TemplateTypeParameterTag 17 | hi def link CxxdTemplateNonTypeParameter TemplateNonTypeParameterTag 18 | hi def link CxxdTemplateTemplateParameter TemplateTemplateParameterTag 19 | hi def link CxxdMacroDefinition MacroDefinitionTag 20 | hi def link CxxdMacroInstantiation MacroInstantiationTag 21 | hi def link CxxdTypedef TypedefTag 22 | hi def link CxxdUsingDirective UsingDirectiveTag 23 | hi def link CxxdUsingDeclaration UsingDeclarationTag 24 | 25 | hi def link QfPreview Pmenu 26 | hi def link QfPreviewTitle Pmenu 27 | hi def link QfPreviewScrollbar PmenuSbar 28 | hi def link QfPreviewThumb PmenuThumb 29 | --------------------------------------------------------------------------------