├── .gitignore ├── CHANGELOG.md ├── Cask ├── LICENSE ├── README.org ├── psc-ide-backported.el ├── psc-ide-flycheck.el ├── psc-ide-protocol.el ├── psc-ide.el └── test ├── psc-ide-test.el └── test-helper.el /.gitignore: -------------------------------------------------------------------------------- 1 | .cask/ 2 | dist/ 3 | *.elc -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | # 2023-10-17 Uses `npx` instead of `npm bin` when `psc-ide-use-npm-bin` is set 4 | - `npm bin` no longer works with node >= 18 5 | - Also adds detection for the new `spago.yaml` project file 6 | 7 | # 2020-05-21 Uses the --editor-mode flag by default 8 | 9 | - It's the better default 10 | 11 | ## 2020-05-21 Removes configuration options to use the non-combined binaries 12 | 13 | - It's been many years now 14 | - Also cleans up some of the documentation and outdated links and references 15 | 16 | ## 2019-03-03 Automatically turn off completion, type on hover, and flycheck if server isn't running 17 | 18 | - To figure out if the server isn't running we remember if the last 19 | connection attempt failed. By triggering an explicit request (asking 20 | for a type explicitly/go-to-definition/manual autocompletion) you 21 | can force a re-check for an externally started server. Running 22 | `psc-ide-server-start` also resets the behaviour. 23 | 24 | ## 2019-01-22 Detect and handle spago projects 25 | 26 | ## 2019-01-15 No longer uses shell-expansion when calling the psc-package command 27 | 28 | - This might mean that Windows users that use a wrapped psc-package executable will 29 | need to put the actual executable on the path 30 | 31 | ## 2018-09-29 Automatically detects psc-package projects and sets globs accordingly 32 | 33 | - `psc-ide-source-globs` should now only specify non-dependency source 34 | files (It's defaulted to `'("src/**/*.purs" "test/**/*.purs")`) 35 | 36 | - The plugin will now detect psc-package projects and call psc-package 37 | sources to determine what source globs to pass to the editor 38 | 39 | - A new `psc-ide-force-user-globs` variable was introduced to override 40 | the new behaviour and force the user specified globs 41 | 42 | ## 2018-05-17 Don't try to fix up temporary paths for flycheck (there shouldn't be any in the compiler output) 43 | ## 2018-05-17 Expand paths relative to the ide servers directory for go-to-definition 44 | 45 | ## 2018-01-01 Fix adding imports for symbols 46 | 47 | ## 2017-11-22 Displays docstrings with company 48 | You can bring up the documentation for the current completion with C-h during 49 | completion 50 | 51 | ## 2017-11-22 Adds `psc-ide-editor-mode` variable 52 | This sets the --editor-mode flag on the server executable if set to true. It 53 | defaults to false for backwards compatibility, but will default to true in a 54 | while 55 | 56 | ## 2017-08-17 57 | - Added a LICENSE file and the appropriate headers 58 | 59 | ## 2017-04-20 60 | - Fixes a bug where large responses would cause psc-ide-send-sync to fail 61 | 62 | ## 2017-04-20 63 | - Displays completions with their already imported qualifiers. This can be toggled 64 | off with `(setq psc-ide-add-qualification-on-completion nil)`. 65 | 66 | - Displays the result of the load command in the message buffer 67 | 68 | ## 2017-04-18 69 | - Switched to purescript-0.11 compatible `purs` executable by default. The 0.10 70 | binaries can be regained with `(setq psc-ide-use-purs nil)`, but we'll remove 71 | this switch when purescript-0.12 is released. 72 | -------------------------------------------------------------------------------- /Cask: -------------------------------------------------------------------------------- 1 | (source gnu) 2 | (source melpa) 3 | 4 | (package-file "psc-ide.el") 5 | 6 | (files "*.el") 7 | 8 | (development 9 | (depends-on "el-mock") 10 | (depends-on "ert-runner")) 11 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | [[http://melpa.org/#/psc-ide][file:http://melpa.org/packages/psc-ide-badge.svg]] 2 | 3 | * psc-ide-emacs 4 | 5 | Emacs integration for [[https://github.com/purescript/purescript/tree/master/psc-ide][psc-ide]] 6 | 7 | ** Installation 8 | 9 | The package is available on [[http://melpa.org/#/psc-ide][MELPA]]. Please read the MELPA's [[http://melpa.org/#/getting-started][Getting Started]] guide 10 | for more information. Once you have MELPA configured install psc-ide-emacs 11 | via =package.el=: 12 | 13 | #+BEGIN_SRC elisp 14 | M-x package-install RET psc-ide RET 15 | #+END_SRC 16 | 17 | ** Configuration 18 | 19 | Add the following to your =~/.emacs=: 20 | 21 | #+BEGIN_SRC elisp 22 | 23 | (require 'psc-ide) 24 | 25 | (add-hook 'purescript-mode-hook 26 | (lambda () 27 | (psc-ide-mode) 28 | (company-mode) 29 | (flycheck-mode) 30 | (turn-on-purescript-indentation))) 31 | #+END_SRC 32 | 33 | If you want to use the psc-ide server that is relative to your ~npm bin~ 34 | directory, e.g. ~./node_modules/.bin/purs~, add this line to your 35 | config: 36 | 37 | #+BEGIN_SRC elisp 38 | (setq psc-ide-use-npm-bin t) 39 | #+END_SRC 40 | 41 | If you would like to use a custom codegen target for your rebuild. (default 42 | is "js") 43 | 44 | There is a `psc-ide-codegen` option that can be set globally in your user config: 45 | 46 | #+BEGIN_SRC elisp 47 | (setq psc-ide-codegen '("corefn")) 48 | #+END_SRC 49 | 50 | or in specific files by addind this to the top of file: 51 | 52 | #+BEGIN_SRC elisp 53 | -- -*- psc-ide-codegen: ("corefn") -*- 54 | #+END_SRC 55 | 56 | 57 | ** Usage 58 | 59 | *** Start the Server ~C-c C-s~ 60 | 61 | *** Load all the modules ~C-c C-l~ 62 | This isn't usually necessary, as the start server command sends a load all 63 | command after starting the server. 64 | *** Get completions from the modules you imported while you type (through ~company-mode~) 65 | [[http://i.imgur.com/8WnRh0s.gif]] 66 | 67 | *** Get completions from all modules in your project with ~company-complete~ 68 | This was bound to ~C-SPC~ in earlier versions but was too intrusive for 69 | usual emacs users so you'll have to bind it to a key of choice. 70 | 71 | eg. ~(global-set-key (kbd "C-SPC") 'company-complete)~ 72 | 73 | [[http://i.imgur.com/LR69MdN.gif]] 74 | 75 | *** Show type for identifier under cursor ~C-c C-t~ 76 | [[http://i.imgur.com/A8cXe9t.gif]] 77 | 78 | Prepending the universal argument expands type synonyms in the displayed 79 | type. 80 | 81 | For example: 82 | ~C-c C-t~ might return ~getName :: Person -> String~ 83 | 84 | If ~Person~ is a type synonym for a record you can use the universal 85 | argument to inspect that record: 86 | 87 | ~C-u C-c C-t~ will then return ~getName :: { name :: String, age :: Int } -> 88 | String~ 89 | 90 | *** Go to definition =M-.= 91 | You can use M-, to jump back to where you came from . If your sourcefiles 92 | are not captured by the default globs you can add a ~.dir-locals.el~ file to 93 | the root of your project, like so: 94 | 95 | #+BEGIN_SRC elisp 96 | ((purescript-mode 97 | . ((psc-ide-source-globs 98 | . ("src/**/*.purs" "test/**/*.purs" "examples/**/*.purs"))))) 99 | #+END_SRC 100 | Modify the globs accordingly and don't worry about dependency 101 | globs for bower, psc-package or spago projects. The plugin picks 102 | these up by default. Check the doc-string for 103 | `psc-ide-source-globs` for some advanced options. 104 | 105 | *** Add an import for the identifier under cursor ~C-c C-i~ 106 | 107 | If the import is ambiguous you will get a selection of modules, from which 108 | you can choose the identifier you want. 109 | 110 | [[http://i.imgur.com/VBXDvPg.gif]] 111 | 112 | *** Add an import on completion (turned on by default) 113 | Can be turned off with: 114 | #+BEGIN_SRC elisp 115 | (customize-set-variable 'psc-ide-add-import-on-completion nil) 116 | #+END_SRC 117 | 118 | [[http://i.imgur.com/r6rl2lT.gif]] 119 | 120 | *** Case Split the given type under cursor ~C-c C-c~ 121 | [[http://i.imgur.com/hTnHxhK.gif]] 122 | *** Add a clause for the function definition under cursor ~C-c C-a~ 123 | [[http://i.imgur.com/VNeC3z8.gif]] 124 | 125 | *** Rebuild the current module and get quick error reporting ~C-c C-b~ 126 | If you set ~(customize-set-variable 'psc-ide-rebuild-on-save t)~ psc-ide will 127 | try to rebuild your module on every save. 128 | 129 | [[http://i.imgur.com/c0L6C4B.gif]] 130 | 131 | *** Flycheck Support 132 | **** Ignore certain errors or warnings 133 | This is determined by the variable ~psc-ide-flycheck-ignored-error-codes~. It can be configured 134 | with ~customize-option~ or similar methods. 135 | 136 | **** Insert suggestion from error ~C-c M-s~ 137 | When the cursor is placed over an error that includes suggestion information, use ~C-c M-s~ to 138 | apply the suggestion. 139 | 140 | *** Keybindings 141 | 142 | | Key | Function | 143 | |-------------+--------------------------------------| 144 | | ~C-c C-s~ | ~psc-ide-server-start~ | 145 | | ~C-c C-q~ | ~psc-ide-server-quit~ | 146 | | ~C-c C-t~ | ~psc-ide-show-type~ | 147 | | ~C-c C-i~ | ~psc-ide-add-import~ | 148 | | ~C-c C-a~ | ~psc-ide-add-clause~ | 149 | | ~C-c C-c~ | ~psc-ide-case-split~ | 150 | | ~C-c C-l~ | ~psc-ide-load-all~ | 151 | | ~C-c C-b~ | ~psc-ide-rebuild~ | 152 | | ~C-c C-S-l~ | ~psc-ide-load-module~ | 153 | | ~C-c M-s~ | ~psc-ide-flycheck-insert-suggestion~ | 154 | -------------------------------------------------------------------------------- /psc-ide-backported.el: -------------------------------------------------------------------------------- 1 | ;;; psc-ide-backported.el --- Backported code from purescript-mode -*- lexical-binding: t -*- 2 | 3 | ;;; Commentary: 4 | 5 | ;; Code ported from purescript-mode 6 | 7 | ;;; Code: 8 | 9 | (require 'cl-lib) 10 | 11 | (defun psc-ide-ident-at-point () 12 | "Return the identifier under point, or nil if none found. 13 | May return a qualified name." 14 | (let ((reg (psc-ide-ident-pos-at-point))) 15 | (when reg 16 | (buffer-substring-no-properties (car reg) (cdr reg))))) 17 | 18 | (defun psc-ide-ident-pos-at-point () 19 | "Return the span of the identifier under point, or nil if none found. 20 | May return a qualified name." 21 | (save-excursion 22 | ;; Skip whitespace if we're on it. That way, if we're at "map ", we'll 23 | ;; see the word "map". 24 | (if (and (not (eobp)) 25 | (eq ? (char-syntax (char-after)))) 26 | (skip-chars-backward " \t")) 27 | 28 | (let ((case-fold-search nil)) 29 | (cl-multiple-value-bind (start end) 30 | (if (looking-at "\\.") 31 | (list (progn (skip-syntax-backward "w_") (point)) 32 | (progn (skip-syntax-forward "w_") (point))) 33 | (if (looking-at "\\s_") 34 | (list (progn (skip-syntax-backward "_") (point)) 35 | (progn (skip-syntax-forward "_") (point))) 36 | (list 37 | (progn (skip-syntax-backward "w'") 38 | (skip-syntax-forward "'") (point)) 39 | (progn (skip-syntax-forward "w'") (point))))) 40 | ;; If we're looking at a module ID that qualifies further IDs, add 41 | ;; those IDs. 42 | (goto-char start) 43 | (while (and (looking-at "[[:upper:]]") (eq (char-after end) ?.) 44 | ;; It's a module ID that qualifies further IDs. 45 | (goto-char (1+ end)) 46 | (save-excursion 47 | (when (not (zerop (skip-syntax-forward 48 | (if (looking-at "\\s_") "_" "w'")))) 49 | (setq end (point)))))) 50 | ;; If we're looking at an ID that's itself qualified by previous 51 | ;; module IDs, add those too. 52 | (goto-char start) 53 | (if (eq (char-after) ?.) (forward-char 1)) ;Special case for "." 54 | (while (and (eq (char-before) ?.) 55 | (progn (forward-char -1) 56 | (not (zerop (skip-syntax-backward "w'")))) 57 | (skip-syntax-forward "'") 58 | (looking-at "[[:upper:]]")) 59 | (setq start (point))) 60 | ;; This is it. 61 | (cons start end))))) 62 | 63 | (provide 'psc-ide-backported) 64 | ;;; psc-ide-backported.el ends here 65 | -------------------------------------------------------------------------------- /psc-ide-flycheck.el: -------------------------------------------------------------------------------- 1 | ;;; psc-ide-flycheck.el --- Flycheck support for the purescript language -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (c) 2015 The psc-ide-emacs authors 4 | ;; License: GNU General Public License version 3, or (at your option) any later version 5 | 6 | ;; Author: Brian Sermons 7 | ;; URL: https://github.com/epost/psc-ide-emacs 8 | 9 | ;;; Commentary: 10 | 11 | ;; Usage: 12 | ;; 13 | ;; (eval-after-load 'flycheck 14 | ;; '(add-hook 'flycheck-mode-hook #'psc-ide-flycheck-setup)) 15 | 16 | ;;; Code: 17 | 18 | (eval-when-compile 19 | (require 'cl-lib) 20 | (require 'let-alist)) 21 | 22 | (require 'seq) 23 | (require 'json) 24 | (require 'dash) 25 | (require 'flycheck) 26 | (require 'psc-ide-protocol) 27 | 28 | 29 | (flycheck-def-option-var psc-ide-flycheck-ignored-error-codes nil psc-ide 30 | "List of errors codes to ignore." 31 | :tag "Flycheck PscIde Ignored Error Codes" 32 | :type '(repeat string)) 33 | 34 | 35 | (defun psc-ide-flycheck-parse-errors (data checker) 36 | "Decode purescript json output errors from DATA with CHECKER." 37 | (let-alist data 38 | (let ((errors) 39 | (resultType (pcase .resultType 40 | (`"success" 'warning) 41 | (_ 'error)))) 42 | (seq-do (lambda (err) 43 | (let-alist err 44 | (unless (member .errorCode psc-ide-flycheck-ignored-error-codes) 45 | (let ((replacePos (if .suggestion.replaceRange 46 | .suggestion.replaceRange 47 | .position))) 48 | 49 | (put-text-property 0 1 :suggestion .suggestion .errorCode) 50 | (put-text-property 0 1 :startLine (cdr (assoc 'startLine replacePos)) .errorCode) 51 | (put-text-property 0 1 :startColumn (cdr (assoc 'startColumn replacePos)) .errorCode) 52 | (put-text-property 0 1 :endLine (cdr (assoc 'endLine replacePos)) .errorCode) 53 | (put-text-property 0 1 :endColumn (cdr (assoc 'endColumn replacePos)) .errorCode) 54 | 55 | (push 56 | (flycheck-error-new-at 57 | .position.startLine 58 | .position.startColumn 59 | resultType 60 | .message 61 | :id .errorCode 62 | :checker checker 63 | :filename .filename) 64 | errors))))) 65 | .result) 66 | errors))) 67 | 68 | ;;;###autoload 69 | (defun psc-ide-flycheck-insert-suggestion () 70 | "Replace error with suggestion from psc compiler." 71 | (interactive) 72 | (-if-let* ((flycheck-err (car (flycheck-overlay-errors-at (point)))) 73 | (suggestion (get-text-property 0 :suggestion (flycheck-error-id flycheck-err))) 74 | (startLine (get-text-property 0 :startLine (flycheck-error-id flycheck-err))) 75 | (startColumn (get-text-property 0 :startColumn (flycheck-error-id flycheck-err))) 76 | (endLine (get-text-property 0 :endLine (flycheck-error-id flycheck-err))) 77 | (endColumn (get-text-property 0 :endColumn (flycheck-error-id flycheck-err)))) 78 | (let* ((start (save-excursion 79 | (goto-char (point-min)) 80 | (forward-line (- startLine 1)) 81 | (move-to-column (- startColumn 1)) 82 | (point))) 83 | (end (save-excursion 84 | (goto-char (point-min)) 85 | (forward-line (- endLine 1)) 86 | (move-to-column (- endColumn 1)) 87 | (point)))) 88 | (progn 89 | (kill-region start end) 90 | (goto-char start) 91 | (let ((new-end 92 | (save-excursion 93 | (let-alist suggestion 94 | (insert (replace-regexp-in-string "\n\\'" "" .replacement))) 95 | (point)))) 96 | (set-mark start) 97 | (goto-char new-end) 98 | (deactivate-mark)) 99 | (save-buffer) 100 | (flycheck-buffer))) 101 | (message "No suggestion available"))) 102 | 103 | (define-key psc-ide-mode-map (kbd "C-c M-s") 104 | 'psc-ide-flycheck-insert-suggestion) 105 | 106 | (defun psc-ide-flycheck-copy-related-files (original temp-file) 107 | (let ((source-js (concat (file-name-sans-extension original) 108 | ".js")) 109 | (target-js (concat (file-name-sans-extension temp-file) 110 | ".js"))) 111 | (when (file-exists-p source-js) 112 | (copy-file source-js target-js t) 113 | (push target-js flycheck-temporaries)))) 114 | 115 | (defun psc-ide-flycheck-start (checker callback) 116 | "Start a psc-ide syntax check with CHECKER. 117 | 118 | CALLBACK is the status callback passed by flycheck." 119 | 120 | (let ((temp-file (flycheck-save-buffer-to-temp #'flycheck-temp-file-system))) 121 | (psc-ide-flycheck-copy-related-files (buffer-file-name) temp-file) 122 | (psc-ide-send (psc-ide-command-rebuild temp-file (buffer-file-name)) 123 | (lambda (result) 124 | (condition-case err 125 | (progn 126 | (let ((errors (psc-ide-flycheck-parse-errors result checker))) 127 | (funcall callback 'finished errors))) 128 | (`(error debug) 129 | (flycheck-safe-delete-temporaries) 130 | (funcall callback 'errored (error-message-string err)))))))) 131 | 132 | (defun psc-ide-flycheck-available-p () 133 | "Return non-nil if we can use the psc-ide flycheck backend in this buffer." 134 | (and psc-ide-mode (psc-ide-server-running-p))) 135 | 136 | (flycheck-define-generic-checker 'psc-ide 137 | "A purescript syntax checker using the `psc-ide' interface." 138 | :start #'psc-ide-flycheck-start 139 | :predicate #'psc-ide-flycheck-available-p 140 | :enabled (lambda () (not psc-ide-disable-flycheck)) 141 | :modes '(purescript-mode)) 142 | 143 | 144 | ;;;###autoload 145 | (defun psc-ide-flycheck-setup () 146 | "Setup Flycheck purescript." 147 | (interactive) 148 | (add-to-list 'flycheck-checkers 'psc-ide)) 149 | 150 | (provide 'psc-ide-flycheck) 151 | ;;; psc-ide-flycheck.el ends here 152 | -------------------------------------------------------------------------------- /psc-ide-protocol.el: -------------------------------------------------------------------------------- 1 | ;;; psc-ide-protocol.el --- Communication with the psc-ide backend -*- lexical-binding: t -*- 2 | 3 | ;; License: GNU General Public License version 3, or (at your option) any later version 4 | 5 | ;;; Commentary: 6 | 7 | ;;; Code: 8 | 9 | (require 'json) 10 | (require 's) 11 | 12 | (defun psc-ide--connect (buffer &optional sentinel) 13 | "Return a network process in the BUFFER connected to the IDE server. 14 | If supplied, SENTINEL is the process state sentinel callback." 15 | (make-network-process 16 | :name "psc-ide-server" 17 | :buffer buffer 18 | :family 'ipv4 19 | :host psc-ide-host 20 | :service psc-ide-port 21 | :sentinel sentinel)) 22 | 23 | (defun psc-ide-test-connection () 24 | "Return non-nil if the server is reachable." 25 | (with-temp-buffer 26 | (ignore-errors 27 | (psc-ide-send psc-ide-command-cwd 'ignore) 28 | t))) 29 | 30 | (defun psc-ide-send-sync (cmd) 31 | (with-temp-buffer 32 | (condition-case nil 33 | (let ((proc (psc-ide--connect (current-buffer)))) 34 | (process-send-string proc (s-prepend cmd "\n")) 35 | 36 | (let ((timed-out nil)) 37 | ;; As long as the process is running and we're not timed out 38 | (while (not (or (string= (process-status proc) "closed") timed-out)) 39 | ;; Wait for the process in a blocking manner for a maximum of 2 40 | ;; seconds, and if we don't receive any output, set timed-out 41 | (unless (accept-process-output proc 2) 42 | (setq timed-out t)))) 43 | 44 | (delete-process proc) 45 | (json-read-from-string (car (s-lines (buffer-string))))) 46 | (error 47 | (error "Couldn't connect to IDE server: you can start it using psc-ide-server-start."))))) 48 | 49 | (defun psc-ide-send (cmd callback) 50 | (let ((buffer (generate-new-buffer "*psc-ide-network-proc*"))) 51 | (condition-case nil 52 | (let ((proc (psc-ide--connect buffer (apply-partially 'psc-ide-wrap-callback callback buffer (current-buffer))))) 53 | (process-send-string proc (s-prepend cmd "\n"))) 54 | ;; Catch all the errors that happen when trying to connect 55 | (error 56 | (progn 57 | (kill-buffer buffer) 58 | (error "Couldn't connect to IDE server: you can start it using psc-ide-server-start.")))))) 59 | 60 | (defun psc-ide-wrap-callback (callback buffer current proc _status) 61 | "Wraps a function that expects a parsed psc-ide response. 62 | Evaluates the CALLBACK in the context of the CURRENT buffer that 63 | initiated call if it still exists." 64 | (when (string= "closed" (process-status proc)) 65 | (let ((parsed 66 | (with-current-buffer buffer 67 | (json-read-from-string 68 | (buffer-substring (point-min) (point-max)))))) 69 | (kill-buffer buffer) 70 | (when (buffer-live-p current) 71 | (with-current-buffer current 72 | (funcall callback parsed)))))) 73 | 74 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 75 | ;; 76 | ;; Protocol commands. 77 | 78 | ;; TODO localise 79 | (defvar psc-ide-command-cwd (json-encode (list :command "cwd"))) 80 | (defvar psc-ide-command-quit (json-encode (list :command "quit"))) 81 | (defvar psc-ide-command-load-all (json-encode (list :command "load"))) 82 | 83 | (defun psc-ide-command-load (modules deps) 84 | (json-encode 85 | (list :command "load" 86 | :params (list 87 | :modules modules 88 | :dependencies deps )))) 89 | 90 | (defun psc-ide-command-show-type (filters search &optional module) 91 | (json-encode 92 | (list :command "type" 93 | :params (append (when filters (list :filters filters)) 94 | (when search (list :search search)) 95 | (when module (list :currentModule module)))))) 96 | 97 | (defun psc-ide-command-complete (filters &optional matcher module options) 98 | (json-encode 99 | (list :command "complete" 100 | :params (append (when filters (list :filters filters)) 101 | (when matcher (list :matcher matcher)) 102 | (when module (list :currentModule module)) 103 | (when options (list :options options)))))) 104 | 105 | (defun psc-ide-command-case-split (line begin end type) 106 | (json-encode 107 | (list :command "caseSplit" 108 | :params (list 109 | :line line 110 | :begin begin 111 | :end end 112 | :annotations json-false 113 | :type type )))) 114 | 115 | (defun psc-ide-command-add-clause (line annotations) 116 | (json-encode 117 | (list :command "addClause" 118 | :params (list 119 | :line line 120 | :annotations (if annotations t json-false))))) 121 | 122 | (defun psc-ide-command-add-import (identifier &optional filters file outfile) 123 | (json-encode 124 | (list :command "import" 125 | :params (list 126 | :file (or file (buffer-file-name)) 127 | :outfile (or outfile (buffer-file-name)) 128 | :filters filters 129 | :importCommand (list 130 | :importCommand "addImport" 131 | :identifier identifier))))) 132 | 133 | (defun psc-ide-command-add-qualified-import (modulename qualifier &optional file outfile) 134 | (json-encode 135 | (list :command "import" 136 | :params (list 137 | :file (or file (buffer-file-name)) 138 | :outfile (or outfile (buffer-file-name)) 139 | :importCommand (list 140 | :importCommand "addQualifiedImport" 141 | :module modulename 142 | :qualifier qualifier))))) 143 | 144 | (defun psc-ide-command-rebuild (&optional filepath actualFile) 145 | (json-encode 146 | (list :command "rebuild" 147 | :params (append (list 148 | :codegen psc-ide-codegen 149 | :file (or filepath (buffer-file-name))) 150 | (when actualFile (list :actualFile actualFile)))))) 151 | 152 | (defun psc-ide-command-list-imports (&optional filepath) 153 | (json-encode 154 | (list :command "list" 155 | :params (list 156 | :type "import" 157 | :file (or filepath (buffer-file-name (current-buffer))))))) 158 | 159 | (defun psc-ide-command-usages (module namespace identifier) 160 | (json-encode 161 | (list :command "usages" 162 | :params (list 163 | :module module 164 | :namespace namespace 165 | :identifier identifier)))) 166 | 167 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 168 | ;; 169 | ;; Protocol utilities. 170 | 171 | (defun psc-ide-generic-filter (name params) 172 | (list :filter name 173 | :params params)) 174 | 175 | (defun psc-ide-filter-exact (filter-str) 176 | (psc-ide-generic-filter "exact" (list :search filter-str))) 177 | 178 | (defun psc-ide-filter-prefix (prefix-str) 179 | (psc-ide-generic-filter "prefix" (list :search prefix-str))) 180 | 181 | (defun psc-ide-filter-modules (modules-list) ;; modules without dependencies 182 | (psc-ide-generic-filter "modules" (list :modules modules-list))) 183 | 184 | (defun psc-ide-filter-dependencies (modules-list) ;; modules with dependencies 185 | (psc-ide-generic-filter "dependencies" (list :modules modules-list))) 186 | 187 | 188 | (defun psc-ide-generic-matcher (name params) 189 | (list :matcher name 190 | :params params)) 191 | 192 | (defun psc-ide-matcher-flex (match-str) 193 | (psc-ide-generic-matcher "flex" (list :search match-str))) 194 | 195 | (defun psc-ide-matcher-distance (match-str max-dist) 196 | (psc-ide-generic-matcher "distance" (list :search match-str 197 | :maxDist max-dist))) 198 | 199 | (defun psc-ide-completion-options (&optional max-results group-reexports) 200 | (append (when max-results (list :maxResults max-results)) 201 | (when group-reexports (list :groupReexports group-reexports)))) 202 | 203 | (defun psc-ide-unwrap-result (res) 204 | "Unwraps the result from psc-ide and in case of an error throws it" 205 | (let ((result-type (cdr (assoc 'resultType res))) 206 | (result (cdr (assoc 'result res)))) 207 | (if (string= result-type "error") (error "%s" result) result))) 208 | 209 | (provide 'psc-ide-protocol) 210 | ;;; psc-ide-protocol.el ends here 211 | -------------------------------------------------------------------------------- /psc-ide.el: -------------------------------------------------------------------------------- 1 | ;;; psc-ide.el --- Minor mode for PureScript's IDE server. -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2020 The psc-ide-emacs authors 4 | ;; License: GNU General Public License version 3, or (at your option) any later version 5 | 6 | 7 | ;; Author : Erik Post 8 | ;; Dmitry Bushenko 9 | ;; Christoph Hegemann 10 | ;; Brian Sermons 11 | ;; Homepage : https://github.com/purescript-emacs/psc-ide-emacs 12 | ;; Version : 0.1.0 13 | ;; Package-Requires: ((emacs "25") (dash "2.18.0") (company "0.8.7") (s "1.10.0") (flycheck "0.24") (let-alist "1.0.4") (seq "1.11") (inheritenv "0.2")) 14 | ;; Keywords : languages 15 | 16 | ;;; Commentary: 17 | 18 | ;; Emacs integration for PureScript's IDE server 19 | 20 | ;;; Code: 21 | 22 | 23 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 24 | ;; 25 | ;; Imports 26 | 27 | (require 'company) 28 | (require 'cl-lib) 29 | (require 'dash) 30 | (require 's) 31 | (require 'inheritenv) 32 | (require 'xref) 33 | (require 'psc-ide-backported) 34 | (require 'psc-ide-protocol) 35 | 36 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 37 | ;; 38 | ;; psc-ide-mode definition 39 | 40 | ;;;###autoload 41 | (define-minor-mode psc-ide-mode 42 | "psc-ide-mode definition" 43 | :lighter (:eval (concat " psc-ide" psc-ide-modeline-state)) 44 | :keymap (let ((map (make-sparse-keymap))) 45 | (define-key map (kbd "C-c C-s") 'psc-ide-server-start) 46 | (define-key map (kbd "C-c C-q") 'psc-ide-server-quit) 47 | (define-key map (kbd "C-c C-l") 'psc-ide-load-all) 48 | (define-key map (kbd "C-c C-S-l") 'psc-ide-load-module) 49 | (define-key map (kbd "C-c C-a") 'psc-ide-add-clause) 50 | (define-key map (kbd "C-c C-c") 'psc-ide-case-split) 51 | (define-key map (kbd "C-c C-i") 'psc-ide-add-import) 52 | (define-key map (kbd "C-c C-t") 'psc-ide-show-type) 53 | (define-key map (kbd "C-c C-b") 'psc-ide-rebuild) 54 | (define-key map (kbd "M-.") 'psc-ide-goto-definition) 55 | (define-key map (kbd "M-,") 'pop-tag-mark) 56 | map) 57 | (if psc-ide-mode 58 | (progn 59 | (setq-local company-tooltip-align-annotations t) 60 | (setq-local eldoc-documentation-function #'psc-ide-show-type-eldoc) 61 | (add-hook 'after-save-hook 'psc-ide-rebuild-on-save-hook nil t)) 62 | (kill-local-variable 'eldoc-documentation-function) 63 | (remove-hook 'after-save-hook 'psc-ide-rebuild-on-save-hook t))) 64 | 65 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 66 | ;; 67 | ;; Settings, override as needed. 68 | 69 | (defgroup psc-ide nil 70 | "Settings for psc-ide." 71 | :prefix "psc-ide-" 72 | :group 'languages) 73 | 74 | (defcustom psc-ide-purs-executable "purs" 75 | "Path to the `purs' executable." 76 | :group 'psc-ide 77 | :type 'string) 78 | 79 | (defcustom psc-ide-use-npm-bin nil 80 | "Whether to use `npm bin' to determine the location of binaries. 81 | This includes the ide server and package manager binaries like spago." 82 | :group 'psc-ide 83 | :type 'boolean) 84 | 85 | (defcustom psc-ide-port 4242 86 | "The port that psc-ide-server uses." 87 | :group 'psc-ide 88 | :type 'integer) 89 | 90 | (defcustom psc-ide-host "localhost" 91 | "The host that psc-ide-server uses." 92 | :group 'psc-ide 93 | :type 'string) 94 | 95 | (defcustom psc-ide-source-globs '("src/**/*.purs" "test/**/*.purs") 96 | "The source globs for your PureScript source files. 97 | By default globs for dependencies from bower, psc-package, or 98 | spago will be appended on starting the server. If you want to 99 | override this behaviour and force JUST these globs take a look at 100 | `psc-ide-force-user-globs`" 101 | :group 'psc-ide 102 | :type '(repeat string)) 103 | 104 | (defcustom psc-ide-force-user-globs nil 105 | "When set forces the exact usage of `psc-ide-source-globs'. 106 | By default this is false, but it's here to support 107 | whatever wacky setup you are running" 108 | :group 'psc-ide 109 | :type 'boolean) 110 | 111 | (defcustom psc-ide-output-directory "output/" 112 | "Path to the output directory. 113 | Defaults to \"output/\" and should only be changed with 114 | .dir-locals.el to accommodate project-specific setups." 115 | :group 'psc-ide 116 | :type 'string) 117 | 118 | (defcustom psc-ide-debug nil 119 | "Makes the server print debug diagnostics into its process buffer." 120 | :group 'psc-ide 121 | :type 'boolean) 122 | 123 | (defcustom psc-ide-add-import-on-completion t 124 | "Whether to add imports on completion." 125 | :group 'psc-ide 126 | :type 'boolean) 127 | 128 | (defcustom psc-ide-add-qualification-on-completion t 129 | "Whether to automatically prepend the qualifier for completions that are 130 | imported qualified in the current module." 131 | :group 'psc-ide 132 | :type 'boolean) 133 | 134 | (defcustom psc-ide-rebuild-on-save nil 135 | "Whether to rebuild files on save and display errors/warnings in a buffer. 136 | If you are using the psc-ide flycheck backend, this setting is 137 | generally redundant, because flycheck will be rebuilding your 138 | files." 139 | :group 'psc-ide 140 | :type 'boolean) 141 | 142 | (defcustom psc-ide-disable-flycheck nil 143 | "Whether to disable flycheck syntax functionality." 144 | :group 'psc-ide 145 | :type 'boolean) 146 | 147 | (defcustom psc-ide-editor-mode t 148 | "Whether to only reload files when the editor initiates rebuilds." 149 | :group 'psc-ide 150 | :type 'boolean) 151 | 152 | (defcustom psc-ide-server-extra-args nil 153 | "Extra arguments to pass to the purs ide executable." 154 | :group 'psc-ide 155 | :type '(repeat string)) 156 | 157 | (defcustom psc-ide-codegen 158 | '("js") 159 | "Codegen used for compilation. 160 | Specified the codegen targets the rebuild should produce. 161 | Uses the same target names as the command line compiler. Defaults to 162 | just JS output" 163 | :group 'psc-ide 164 | :type '(repeat string)) 165 | 166 | (defconst psc-ide-import-regex 167 | (rx (and line-start "import" (1+ space) 168 | (group (and (1+ (any word ".")))) 169 | (opt (1+ space) "hiding") 170 | (opt (1+ space) "(" (group (0+ not-newline)) ")") 171 | (opt (1+ space) "as" (1+ space) (group (and (1+ (any word ".")))))))) 172 | 173 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 174 | 175 | ;; Interactive. 176 | 177 | (defun psc-ide-rebuild-on-save-hook() 178 | "Rebuilds the current module on save." 179 | (when psc-ide-rebuild-on-save 180 | (psc-ide-rebuild))) 181 | 182 | (with-eval-after-load 'flycheck 183 | (require 'psc-ide-flycheck) 184 | (psc-ide-flycheck-setup)) 185 | 186 | (defun company-psc-ide-backend (command &optional arg &rest _ignored) 187 | "The psc-ide backend for `company-mode'. 188 | COMMAND, ARG and IGNORED correspond to the standard company backend API." 189 | (interactive (list 'interactive)) 190 | 191 | (when (and psc-ide-mode 192 | ;; Don't complete as the user types when we think the 193 | ;; server isn't available, but do try if they explicitly 194 | ;; requested the completion 195 | (or company--manual-action (psc-ide-server-running-p))) 196 | (cl-case command 197 | (interactive (company-begin-backend 'company-psc-ide-backend)) 198 | 199 | (prefix (unless (company-in-string-or-comment) 200 | (let ((symbol (company-grab-symbol))) 201 | (if symbol 202 | ;; We strip of the qualifier so that it doesn't get 203 | ;; overwritten when completing. 204 | (if (s-contains-p "." symbol) 205 | (cons (car (last (s-split "\\." symbol))) t) 206 | symbol) 207 | 'stop)))) 208 | 209 | (candidates (psc-ide-company-fetcher arg company--manual-action)) 210 | 211 | (doc-buffer (company-doc-buffer (get-text-property 0 :documentation arg))) 212 | 213 | (sorted t) 214 | 215 | (annotation (psc-ide-annotation arg)) 216 | 217 | (meta (psc-ide-string-fontified (get-text-property 0 :type arg))) 218 | 219 | (post-completion 220 | (unless (or 221 | ;; Don't add an import when the option to do so is disabled 222 | (not psc-ide-add-import-on-completion) 223 | ;; or when a qualified identifier was completed 224 | (or (get-text-property 0 :qualifier arg) (s-contains-p "." (company-grab-symbol))) 225 | ;; Don't attempt to import Prim members 226 | (string= (get-text-property 0 :module arg) "Prim")) 227 | (psc-ide-add-import-impl arg (vector 228 | (psc-ide-filter-modules 229 | (list (get-text-property 0 :module arg)))))))))) 230 | 231 | (defun psc-ide-server-start (root) 232 | "Start `psc-ide-server' in the ROOT directory and load all modules." 233 | (interactive (list (read-directory-name "Project root: " (psc-ide-suggest-project-dir)))) 234 | (let ((default-directory root)) 235 | (psc-ide-server-start-impl root (unless psc-ide-force-user-globs 236 | (psc-ide--server-start-globs)))) 237 | (run-at-time "1 sec" nil 'psc-ide-load-all)) 238 | 239 | (defun psc-ide-server-quit () 240 | "Quit `psc-ide-server'." 241 | (interactive) 242 | (psc-ide-send-sync psc-ide-command-quit)) 243 | 244 | (defun psc-ide--server-start-globs () 245 | "Detects PURS_IDE_SOURCES or package manager setup to set purs ide source globs" 246 | (append 247 | psc-ide-source-globs 248 | (pcase (getenv "PURS_IDE_SOURCES") 249 | ((and (pred stringp) globs) 250 | (message "Using source globs from PURS_IDE_SOURCES") 251 | (split-string globs "[\r\n\s]+" t)) 252 | (_ (inheritenv (psc-ide-server-use-package-manager-globs)))))) 253 | 254 | (defun psc-ide-server-use-package-manager-globs () 255 | "Detects bower, psc-package and spago projects and determines sensible 256 | source globs." 257 | (pcase (seq-filter 'file-exists-p '("psc-package.json" "bower.json" "spago.dhall" "spago.yaml")) 258 | ('() 259 | (message "Couldn't find psc-package.json, bower.json nor spago.dhall files, using just the user specified globs.") 260 | nil) 261 | ('("psc-package.json") (psc-ide--psc-package-globs)) 262 | ('("bower.json") (psc-ide--bower-globs)) 263 | ('("spago.dhall") (psc-ide--spago-globs)) 264 | ('("spago.yaml") (psc-ide--spago-globs)) 265 | (found-package-files 266 | (message 267 | (concat "Detected multiple project files: " 268 | (mapconcat 'identity found-package-files ", "))) 269 | nil))) 270 | 271 | (defun psc-ide--psc-package-globs () 272 | "Add file globs for psc-package projects." 273 | (psc-ide--parse-globs 274 | "*PSC-PACKAGE SOURCES*" 275 | "*PSC-PACKAGE ERRORS*" 276 | '(("cmd" . "psc-package") 277 | ("args" . ("sources"))))) 278 | 279 | (defun psc-ide--spago-globs () 280 | "Add file globs for spago projects." 281 | (psc-ide--parse-globs 282 | "*SPAGO SOURCES*" 283 | "*SPAGO ERRORS*" 284 | (if psc-ide-use-npm-bin 285 | '(("cmd" . "npx") 286 | ("args" . ("spago" "sources"))) 287 | '(("cmd" . "spago") 288 | ("args" . ("sources")))))) 289 | 290 | (defun psc-ide--bower-globs () 291 | "Add file globs for bower projects." 292 | '("bower_components/purescript-*/src/**/*.purs")) 293 | 294 | (defun psc-ide--parse-globs (results errors cmd-alist) 295 | "Return the globs printed by a command. 296 | RESULTS and ERRORS are buffer names. 297 | CMD-ALIST is a command name and its arguments, e.g. ((\"cmd\" . 298 | \"psc-package\") (\"args\" . (\"sources\")))" 299 | (let* (server-globs (err-file (make-temp-file "psc-ide-globs")) 300 | (cmd (cdr (assoc "cmd" cmd-alist))) 301 | (cmd-args (cdr (assoc "args" cmd-alist)))) 302 | (unwind-protect 303 | (if (zerop (apply 'call-process cmd nil (list results err-file) nil cmd-args)) 304 | (progn 305 | (with-current-buffer (get-buffer results) 306 | (setq server-globs (split-string (buffer-string) "[\r\n]+" t)) 307 | (delete-windows-on results) 308 | (kill-buffer results)) 309 | (message (format "Parsed source globs from %s. Starting server..." cmd))) 310 | (with-current-buffer (get-buffer-create errors) 311 | (let ((inhibit-read-only t)) 312 | (insert-file-contents err-file nil nil nil t)) 313 | (special-mode) 314 | (display-buffer (current-buffer)) 315 | (error (format "Error executing %s" cmd)))) 316 | (delete-file err-file)) 317 | server-globs)) 318 | 319 | (defun psc-ide-load-module (module-name) 320 | "Load module with MODULE-NAME." 321 | (interactive (list (read-string "Module: " (psc-ide-get-module-name)))) 322 | (psc-ide-load-module-impl module-name)) 323 | 324 | (defun psc-ide-load-all () 325 | "Load all modules in the current project." 326 | (interactive) 327 | (psc-ide-send psc-ide-command-load-all 328 | (-compose 'message 'psc-ide-unwrap-result))) 329 | 330 | (defun psc-ide-show-type (expand) 331 | "Show type of the symbol under cursor and EXPAND its type synonyms." 332 | (interactive "P") 333 | (psc-ide-show-type-impl (psc-ide-ident-at-point) t expand)) 334 | 335 | (defun psc-ide-goto-definition () 336 | "Go to definition of the symbol under cursor." 337 | (interactive) 338 | (let ((ident (psc-ide-ident-at-point))) 339 | (psc-ide-goto-definition-impl ident))) 340 | 341 | (defun psc-ide-case-split (type) 342 | "Case Split on identifier under cursor while specifying TYPE." 343 | (interactive "sType: ") 344 | (let ((new-lines (psc-ide-case-split-impl type))) 345 | (beginning-of-line) (kill-line) ;; clears the current line 346 | (insert (mapconcat 'identity new-lines "\n")))) 347 | 348 | (defun psc-ide-add-clause () 349 | "Add clause on identifier under cursor." 350 | (interactive) 351 | (let ((new-lines (psc-ide-add-clause-impl))) 352 | (beginning-of-line) (kill-line) ;; clears the current line 353 | (insert (mapconcat 'identity new-lines "\n")))) 354 | 355 | (defun psc-ide-add-import () 356 | "Add an import for the symbol under the cursor." 357 | (interactive) 358 | (-if-let (splitted (psc-ide-split-qualifier (psc-ide-ident-at-point))) 359 | (let-alist splitted 360 | (psc-ide-add-import-qualified-impl .identifier .qualifier)) 361 | (psc-ide-add-import-impl (psc-ide-ident-at-point)))) 362 | 363 | (defun psc-ide-rebuild () 364 | "Rebuild the current module." 365 | (interactive) 366 | (save-buffer) 367 | (psc-ide-send (psc-ide-command-rebuild) 'psc-ide-rebuild-handler)) 368 | 369 | (defun psc-ide-rebuild-handler (response) 370 | "Handle a rebuild RESPONSE. 371 | Either displays errors/warnings inside the *psc-ide-rebuild* 372 | buffer, or closes it if there were none." 373 | (let ((is-success (string= "success" (cdr (assoc 'resultType response)))) 374 | (result (cdr (assoc 'result response)))) 375 | (if (not is-success) 376 | (psc-ide-display-rebuild-message "Error" (aref result 0)) 377 | (if (<= (length result) 0) 378 | ;; If there are no warnings we close the rebuild buffer and print "OK" 379 | (progn 380 | (delete-windows-on (get-buffer-create "*psc-ide-rebuild*")) 381 | (message "OK")) 382 | (psc-ide-display-rebuild-message "Warning" (aref result 0)))))) 383 | 384 | (defun psc-ide-display-rebuild-message (error-type raw-message) 385 | "Take a parsed JSON error/warning and displays it in the rebuild buffer. 386 | ERROR-TYPE is either \"error\" or \"warning\" and gets displayed with 387 | the RAW-MESSAGE." 388 | (let ((msg (concat error-type ": " (psc-ide-pretty-json-error raw-message)))) 389 | (progn 390 | (with-current-buffer (get-buffer-create "*psc-ide-rebuild*") 391 | (compilation-mode) 392 | (read-only-mode -1) 393 | (erase-buffer) 394 | (insert msg) 395 | (read-only-mode 1)) 396 | (display-buffer "*psc-ide-rebuild*") 397 | (set-window-point (get-buffer-window "*psc-ide-rebuild*") (point-min))))) 398 | 399 | (defun psc-ide-pretty-json-error (purs-error) 400 | "Formats a parsed PURS-ERROR for display inside a compilation buffer." 401 | (let-alist purs-error 402 | (if (not .position) 403 | .message 404 | (concat .filename 405 | ":" (number-to-string .position.startLine) 406 | ":" (number-to-string .position.startColumn) 407 | ":" "\n" .message)))) 408 | 409 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 410 | ;; 411 | ;; Non-interactive. 412 | 413 | (defun psc-ide-show-type-eldoc () 414 | "Show type of the symbol under cursor, but be quiet about failures." 415 | (when (psc-ide-server-running-p) 416 | (psc-ide-show-type-impl (psc-ide-ident-at-point)))) 417 | 418 | (defun psc-ide-case-split-impl (type) 419 | "Case Split on identifier of TYPE under cursor." 420 | (let ((reg (psc-ide-ident-pos-at-point))) 421 | (psc-ide-unwrap-result (psc-ide-send-sync 422 | (psc-ide-command-case-split 423 | (substring (thing-at-point 'line t) 0 -1) 424 | (save-excursion (goto-char (car reg)) (current-column)) 425 | (save-excursion (goto-char (cdr reg)) (current-column)) 426 | type))))) 427 | 428 | (defun psc-ide-add-clause-impl () 429 | "Add clause on identifier under cursor." 430 | (psc-ide-unwrap-result (psc-ide-send-sync 431 | (psc-ide-command-add-clause 432 | (substring (thing-at-point 'line t) 0 -1) nil)))) 433 | 434 | (defun psc-ide-get-module-name () 435 | "Return the qualified name of the module in the current buffer." 436 | (save-excursion 437 | (save-restriction 438 | (widen) 439 | (goto-char (point-min)) 440 | (when (re-search-forward "^module +\\([A-Z][A-Za-z0-9.]*\\)" nil t) 441 | (buffer-substring-no-properties (match-beginning 1) (match-end 1)))))) 442 | 443 | (defun psc-ide-extract-import-from-match-data (&optional string) 444 | "Helper to extract the relevant info when using the `psc-ide-import-regex'. 445 | STRING is for use when the search used was with `string-match'." 446 | (let (result) 447 | (push `(module . ,(match-string-no-properties 1 string)) result) 448 | (push `(qualifier . ,(match-string-no-properties 3 string)) result) 449 | result)) 450 | 451 | (defun psc-ide-parse-imports-in-buffer (&optional buffer) 452 | "Parse the list of imports for the current purescript BUFFER." 453 | (let ((module-name (psc-ide-get-module-name)) 454 | (matches)) 455 | (save-match-data 456 | (save-excursion 457 | (with-current-buffer (or buffer (current-buffer)) 458 | (save-restriction 459 | (widen) 460 | (goto-char (point-min)) 461 | (when module-name 462 | (push `((module . ,module-name)) matches)) 463 | (while (search-forward-regexp psc-ide-import-regex nil t 1) 464 | (push (psc-ide-extract-import-from-match-data) matches)))))) 465 | matches)) 466 | 467 | 468 | (defun psc-ide-ask-project-dir () 469 | "Ask psc-ide server for the project dir." 470 | (interactive) 471 | (psc-ide-send psc-ide-command-cwd 472 | (-compose 'message 'psc-ide-unwrap-result))) 473 | 474 | (defconst psc-ide-server-buffer-name "*psc-ide-server*" 475 | "Name of the buffer in which the IDE server process should run.") 476 | 477 | (defun psc-ide-server-start-impl (dir-name &optional globs) 478 | "Start psc-ide server in DIR-NAME with the given source GLOBS." 479 | (let ((cmd (psc-ide-server-command dir-name globs))) 480 | (with-current-buffer (get-buffer-create psc-ide-server-buffer-name) 481 | (let ((previous (get-buffer-process (current-buffer)))) 482 | (when (and previous (process-live-p previous)) 483 | (kill-process previous))) 484 | (let ((proc (apply 'start-process "server" (current-buffer) cmd))) 485 | (set-process-query-on-exit-flag proc nil)) 486 | (special-mode)))) 487 | 488 | (defvar-local psc-ide-modeline-state nil 489 | "A string for use in the modeline to indicate the server state. 490 | This is updated by `psc-ide-server-running-p'.") 491 | 492 | (defun psc-ide-server-running-p () 493 | "Return non-nil if the server is running." 494 | (let ((running (psc-ide-test-connection))) 495 | (setq psc-ide-modeline-state (if running "" "[STOPPED]")) 496 | running)) 497 | 498 | (defun psc-ide-server-command (dir-name &optional globs) 499 | "Build a shell command to start `purs ide' in directory DIR-NAME. 500 | Tries to find the purs executable and builds up the command by 501 | appending eventual options. Returns a list that can be expanded 502 | and passed to `start-process`. 503 | 504 | If supplied, GLOBS are the source file globs for this project." 505 | (let* ((path (psc-ide-executable-path)) 506 | (cmd `(,@path "ide" "server")) 507 | (port (number-to-string psc-ide-port)) 508 | (directory (expand-file-name dir-name)) 509 | (debug-flags (when psc-ide-debug '("--log-level" "debug"))) 510 | (editor-mode (when psc-ide-editor-mode '("--editor-mode"))) 511 | (source-globs (or globs psc-ide-source-globs))) 512 | (if path 513 | (remove nil `(,@cmd "-p" ,port "-d" ,directory 514 | "--output-directory" ,psc-ide-output-directory 515 | ,@editor-mode 516 | ,@debug-flags ,@psc-ide-server-extra-args 517 | ,@source-globs)) 518 | (error (concat "Couldn't locate purs executable. You" 519 | " could either customize the psc-ide-purs-executable," 520 | " set the psc-ide-use-npm-bin variable to" 521 | " true, or put the executable on your path."))))) 522 | 523 | (defun psc-ide-executable-path () 524 | "Return the full path to the IDE server executable." 525 | (if psc-ide-use-npm-bin 526 | '("npx" "purs") 527 | (list (executable-find psc-ide-purs-executable)))) 528 | 529 | (defun psc-ide-server-version () 530 | "Return the version of the found psc-ide-server executable." 531 | (let ((path (psc-ide-executable-path))) 532 | (s-chomp (shell-command-to-string (s-concat path " --version"))))) 533 | 534 | (defun psc-ide-load-module-impl (module-name) 535 | "Load a PureScript module with MODULE-NAME and its dependencies." 536 | (psc-ide-send (psc-ide-command-load 537 | [] (list module-name)) 538 | (-compose 'message 'psc-ide-unwrap-result))) 539 | 540 | (defun psc-ide-add-import-impl (identifier &optional filters) 541 | "Invoke the addImport command for IDENTIFIER with the given FILTERS." 542 | (let* ((tmp-file (make-temp-file "psc-ide-add-import")) 543 | (result (progn 544 | (write-region (point-min) (point-max) tmp-file) 545 | (psc-ide-unwrap-result 546 | (psc-ide-send-sync (psc-ide-command-add-import identifier filters tmp-file tmp-file)))))) 547 | (if (not (stringp result)) 548 | (let ((selection 549 | (completing-read "Which Module to import from: " 550 | (seq-map (lambda (x) 551 | (cdr (assoc 'module x))) result)))) 552 | (psc-ide-add-import-impl identifier (vector (psc-ide-filter-modules (vector selection))))) 553 | (progn (message "Added import for %s" identifier) 554 | (save-restriction 555 | (widen) 556 | ;; command successful, insert file with replacement to preserve 557 | ;; markers. 558 | (insert-file-contents tmp-file nil nil nil t)))) 559 | (delete-file tmp-file))) 560 | 561 | (defun psc-ide-add-import-qualified-impl (identifier qualifier) 562 | "Add a qualified import for the given IDENTIFIER and QUALIFIER." 563 | (let* ((completions 564 | (psc-ide-unwrap-result 565 | (psc-ide-send-sync 566 | (psc-ide-command-show-type (vector) identifier)))) 567 | (module 568 | (pcase (length completions) 569 | (`0 (error "Couldn't find a module for %s" identifier)) 570 | (`1 (cdr (assoc 'module (aref completions 0)))) 571 | (_ (completing-read "Which Module: " 572 | (seq-map (lambda (x) (let-alist x .module)) completions)))))) 573 | (unless (string= (psc-ide-qualifier-for-module module) qualifier) 574 | (save-buffer) 575 | (psc-ide-send-sync (psc-ide-command-add-qualified-import module qualifier)) 576 | (revert-buffer nil t)))) 577 | 578 | (defun psc-ide-company-fetcher (_ &optional manual) 579 | "Create an asynchronous company fetcher. 580 | Grabs the symbol at point at creates an asynchronous completer. 581 | We ignore the prefix we get from company, because it doesn't 582 | contain eventual qualifiers. MANUAL is as per 583 | `psc-ide-complete-async'." 584 | (let ((prefix (company-grab-symbol))) 585 | `(:async . ,(apply-partially 'psc-ide-complete-async prefix manual)))) 586 | 587 | (defun psc-ide-complete-async (prefix manual callback) 588 | "Sends a completion command for PREFIX to purs ide. 589 | If MANUAL is set, do not filter with the currently imported modules. 590 | CALLBACK receives the asynchronously retrieved completions." 591 | (let ((command (psc-ide-build-completion-command prefix manual)) 592 | (handler (apply-partially 'psc-ide-handle-completionresponse prefix callback))) 593 | (psc-ide-send command handler))) 594 | 595 | (defun psc-ide-split-qualifier (s) 596 | "Split S into (qualifier . identifier), or return nil if there is no qualifier." 597 | (let* ((splitted (s-split "\\." s)) 598 | (qualifier (s-join "." (butlast splitted))) 599 | (identifier (-last-item splitted))) 600 | (when (and identifier (not (string= "" qualifier)) (s-uppercase? (substring qualifier 0 1))) 601 | `((identifier . ,identifier) 602 | (qualifier . ,qualifier))))) 603 | 604 | (defun psc-ide-find-usages (symbol) 605 | "Find usages of SYMBOL." 606 | (let ((declaration (elt (psc-ide-unwrap-result 607 | (psc-ide-send-sync (psc-ide-build-completion-command symbol nil))) 608 | 0))) 609 | (when declaration 610 | (let-alist declaration 611 | (psc-ide-unwrap-result (psc-ide-send-sync 612 | (psc-ide-command-usages 613 | .module 614 | "value" 615 | (-if-let (qualified (psc-ide-split-qualifier symbol)) 616 | (alist-get 'identifier qualified ) 617 | symbol)))))))) 618 | 619 | (defun psc-ide-build-completion-command (search manual) 620 | "Construct a completion command from the given SEARCH. 621 | 622 | If MANUAL is set, ignore the currently imported modules. 623 | 624 | The cases we have to cover: 625 | 1. List.fil <- filter by prefix and List module 626 | 2. fil| + manual <- don't filter at all 627 | 3. fil| <- filter by prefix and imported modules" 628 | (let* ((components (s-split "\\." search)) 629 | (prefix (car (last components))) 630 | (qualifier (s-join "." (butlast components)))) 631 | (if (not (s-blank? qualifier)) 632 | ;; 1. List.fil <- filter by prefix and List module 633 | (psc-ide-qualified-completion-command prefix qualifier) 634 | (if manual 635 | ;; 2. fil| + manual <- don't filter at all 636 | (psc-ide-command-complete 637 | (vector (psc-ide-filter-prefix prefix)) 638 | nil 639 | (psc-ide-get-module-name)) 640 | ;; 3. fil| <- filter by prefix and imported modules" 641 | (psc-ide-command-complete 642 | (vector (psc-ide-filter-prefix prefix) 643 | (psc-ide-filter-modules (cons "Prim" (psc-ide-all-imported-modules)))) 644 | nil 645 | (psc-ide-get-module-name)))))) 646 | 647 | (defun psc-ide-qualified-completion-command (prefix qualifier) 648 | "Build a completion command for a PREFIX with QUALIFIER." 649 | (let ((modules (psc-ide-modules-for-qualifier qualifier))) 650 | (psc-ide-command-complete 651 | (vector (psc-ide-filter-prefix prefix) 652 | (psc-ide-filter-modules (vconcat modules))) 653 | nil 654 | (psc-ide-get-module-name)))) 655 | 656 | (defun psc-ide-all-imported-modules () 657 | "Retrieve all imported modules for a buffer." 658 | (seq-map (lambda (import) (cdr (assoc 'module import))) 659 | (psc-ide-parse-imports-in-buffer))) 660 | 661 | (defun psc-ide-modules-for-qualifier (qualifier) 662 | "Search the current module's imports for modules that are qualified as QUALIFIER." 663 | (let ((imports (psc-ide-parse-imports-in-buffer))) 664 | (-keep (lambda (import) 665 | (when (equal qualifier (cdr (assoc 'qualifier import))) 666 | (cdr (assoc 'module import)))) imports))) 667 | 668 | (defun psc-ide-qualifier-for-module (module &optional parsed-imports) 669 | "Search the current module's imports for MODULE and return its qualifier. 670 | Return nil if the module is not imported qualified. Does not 671 | reparse if PARSED-IMPORTS is passed." 672 | (let ((imports (or parsed-imports (psc-ide-parse-imports-in-buffer)))) 673 | (car 674 | (-keep (lambda (import) 675 | (when (equal module (cdr (assoc 'module import))) 676 | (cdr (assoc 'qualifier import)))) imports)))) 677 | 678 | (defun psc-ide-handle-completionresponse (prefix callback response) 679 | "Handle a completion response from psc-ide for PREFIX. 680 | Accepts a CALLBACK and a completion RESPONSE from psc-ide, 681 | processes the response into a format suitable for company and 682 | passes it into the callback" 683 | (let* ((result (psc-ide-unwrap-result response)) 684 | (completions (seq-map (apply-partially 'psc-ide-annotate-completion prefix (psc-ide-parse-imports-in-buffer)) result))) 685 | (funcall callback completions))) 686 | 687 | (defun psc-ide-annotate-completion (prefix parsed-imports completion) 688 | "Annotate a completion for PREFIX from psc-ide with `text-properties'. 689 | PARSED-IMPORTS are used to annotate the COMPLETION with qualifiers." 690 | (let-alist completion 691 | (let* ((qualifier (psc-ide-qualifier-for-module .module parsed-imports)) 692 | (identifier (if (and psc-ide-add-qualification-on-completion 693 | qualifier 694 | ;; Don't add a qualifier if we're already 695 | ;; completing a qualified prefix 696 | (not (s-contains-p "." prefix))) 697 | (format "%s.%s" qualifier .identifier) 698 | .identifier))) 699 | 700 | (add-text-properties 0 1 (list :type .type 701 | :module .module 702 | :qualifier qualifier 703 | :documentation .documentation) identifier) 704 | ;; add-text-properties is side-effecting and doesn't return the modified 705 | ;; string, so we need to explicitly return the identifier from here 706 | identifier))) 707 | 708 | (defun psc-ide-goto-definition-impl (search) 709 | "Asks for the definition location of SEARCH and jumps to it." 710 | (let* ((resp (psc-ide-send-sync 711 | (psc-ide-build-type-command search))) 712 | (result (psc-ide-unwrap-result resp))) 713 | (when (not (zerop (length result))) 714 | (let* ((completion (aref result 0)) 715 | (position (cdr (assoc 'definedAt completion)))) 716 | (if position 717 | (let* ((file (cdr (assoc 'name position))) 718 | (start (cdr (assoc 'start position))) 719 | (line (aref start 0)) 720 | (column (aref start 1))) 721 | (if (fboundp 'xref-push-marker-stack) ;; Emacs 25 722 | (xref-push-marker-stack) 723 | (with-no-warnings 724 | (require 'etags) 725 | (ring-insert find-tag-marker-ring (point-marker)))) 726 | (find-file (psc-ide-expand-file-name file)) 727 | (goto-char (point-min)) 728 | (forward-line (1- line)) 729 | (forward-char (1- column))) 730 | (message (format "No position information for %s" search))))))) 731 | 732 | (defun psc-ide-expand-file-name (file) 733 | "Expands a FILE name to be relative to the ide servers cwd. 734 | Is a no-op if the path is absolute" 735 | (if (file-name-absolute-p file) 736 | file 737 | (expand-file-name 738 | file 739 | (psc-ide-unwrap-result (psc-ide-send-sync psc-ide-command-cwd))))) 740 | 741 | (defun psc-ide-show-type-impl (search &optional warn expand) 742 | "Print a message that describes the type of SEARCH. 743 | If the type of SEARCH is not found it prints a warning depending 744 | on whether WARN is true. Optionally EXPANDs type synonyms." 745 | (let ((handler 746 | (lambda (resp) 747 | (let ((result (psc-ide-unwrap-result resp))) 748 | (if (not (zerop (length result))) 749 | (let-alist (aref result 0) 750 | (message (psc-ide-string-fontified 751 | (format "%s.%s ∷\n %s" 752 | .module 753 | .identifier 754 | (if expand .expandedType .type))))) 755 | (when warn (message "Know nothing about type of `%s'." search))))))) 756 | (psc-ide-send (psc-ide-build-type-command search) handler))) 757 | 758 | (defun psc-ide-build-type-command (search) 759 | "Builds a type command from SEARCH." 760 | (let* ((components (s-split "\\." search)) 761 | (ident (car (last components))) 762 | (qualifier (s-join "." (butlast components)))) 763 | (if (not (s-blank? qualifier)) 764 | (psc-ide-qualified-type-command ident qualifier) 765 | (psc-ide-command-show-type 766 | (vector (psc-ide-filter-modules 767 | (cons "Prim" (psc-ide-all-imported-modules)))) 768 | search 769 | (psc-ide-get-module-name))))) 770 | 771 | (defun psc-ide-qualified-type-command (ident qualifier) 772 | "Build a type command for an IDENT with QUALIFIER." 773 | (let ((modules (psc-ide-modules-for-qualifier qualifier))) 774 | (psc-ide-command-show-type 775 | (vector (psc-ide-filter-modules (vconcat modules))) 776 | ident 777 | (psc-ide-get-module-name)))) 778 | 779 | (defun psc-ide-annotation (s) 780 | "Extract the module annotation from S." 781 | (format " (%s)" (get-text-property 0 :module s))) 782 | 783 | (defun psc-ide-suggest-project-dir () 784 | "Suggest a project directory to start the ide server in." 785 | (if (and (fboundp 'projectile-project-root) 786 | (fboundp 'projectile-project-p) 787 | (projectile-project-p)) 788 | (projectile-project-root) 789 | default-directory)) 790 | 791 | (defun psc-ide-string-fontified (string) 792 | "Take a STRING and return it with syntax highlighting." 793 | (if (fboundp 'turn-on-purescript-font-lock) 794 | (with-temp-buffer 795 | (turn-on-purescript-font-lock) 796 | (insert string) 797 | (font-lock-ensure) 798 | (buffer-string)) 799 | string)) 800 | 801 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 802 | ;; 803 | ;; Utilities 804 | 805 | (add-to-list 'company-backends 'company-psc-ide-backend) 806 | 807 | ;; xref-backend 808 | ;;;###autoload 809 | (defun psc-ide-xref-backend () 810 | "Xref backend for psc-ide." 811 | (when psc-ide-mode 'psc-ide)) 812 | 813 | (cl-defmethod xref-backend-identifier-at-point ((_backend (eql psc-ide))) 814 | (psc-ide-ident-at-point)) 815 | 816 | (cl-defmethod xref-backend-identifier-completion-table ((_backend (eql psc-ide))) 817 | nil) 818 | 819 | (cl-defmethod xref-backend-definitions ((_backend (eql psc-ide)) _symbol) 820 | (psc-ide-goto-definition)) 821 | 822 | (cl-defmethod xref-backend-references ((_backend (eql psc-ide)) symbol) 823 | (let* ((usages (psc-ide-find-usages symbol)) 824 | (basedir (psc-ide-unwrap-result (psc-ide-send-sync psc-ide-command-cwd)))) 825 | (seq-map (lambda (usage) 826 | (let-alist usage 827 | (xref-make 828 | "" 829 | (xref-make-file-location 830 | ;; The compiler only stores paths relative to the project root in some cases 831 | (if (file-exists-p .name) .name (concat (file-name-as-directory basedir) .name)) 832 | (elt .start 0) 833 | (elt .start 1))))) 834 | usages))) 835 | 836 | (add-hook 'xref-backend-functions 'psc-ide-xref-backend) 837 | 838 | (provide 'psc-ide) 839 | 840 | ;;; psc-ide.el ends here 841 | -------------------------------------------------------------------------------- /test/psc-ide-test.el: -------------------------------------------------------------------------------- 1 | (require 'psc-ide) 2 | 3 | (defconst psc-ide-test-example-imports " 4 | module Main where 5 | 6 | import Prelude hiding (compose) 7 | 8 | import Control.Monad.Aff (Aff(), runAff, later') 9 | import Control.Monad.Eff (Eff()) 10 | import Control.Monad.Eff.Exception (throwException) 11 | import Halogen hiding (get, set) as H 12 | 13 | import Halogen.Util (appendToBody, onLoad) 14 | import Halogen.HTML.Indexed as Hd 15 | import Halogen.HTML.Properties.Indexed (key, href) as P 16 | import Halogen.HTML.Events.Indexed as P 17 | 18 | ") 19 | 20 | (defun psc-ide-test-example-with-buffer (f) 21 | (with-temp-buffer 22 | (insert psc-ide-test-example-imports) 23 | (goto-char 0) 24 | (funcall f))) 25 | 26 | (defun psc-ide-test-parse-example-imports () 27 | (psc-ide-test-example-with-buffer 28 | (lambda () (psc-ide-parse-imports-in-buffer)))) 29 | 30 | ;; Module import parsing tests 31 | 32 | (ert-deftest test-get-import-matches-in-buffer-should-return-all-imports () 33 | (with-temp-buffer 34 | (insert psc-ide-test-example-imports) 35 | (goto-char 0) 36 | (let ((matches (psc-ide-parse-imports-in-buffer))) 37 | (should (= 10 (length matches)))))) 38 | 39 | (defun test-import (import name as) 40 | (string-match psc-ide-import-regex import) 41 | (let* ((import (psc-ide-extract-import-from-match-data import))) 42 | (should (equal (assoc 'module import) (cons 'module name))) 43 | (should (equal (assoc 'qualifier import) (cons 'qualifier as))))) 44 | 45 | (ert-deftest test-get-import-from-match-data-full () 46 | (test-import "import Mod.SubMod (foo, bar) as El" 47 | "Mod.SubMod" 48 | "El")) 49 | 50 | (ert-deftest test-match-import-single-module () 51 | (test-import "import Foo" "Foo" nil)) 52 | 53 | (ert-deftest test-match-import-with-qualifier () 54 | (test-import "import Foo as F" "Foo" "F")) 55 | 56 | (ert-deftest test-match-import-with-single-expose () 57 | (test-import "import Foo (test)" "Foo" nil)) 58 | 59 | (ert-deftest test-match-import-with-multiple-exposings-tight () 60 | (test-import "import Foo (test1,test2)" "Foo" nil)) 61 | 62 | (ert-deftest test-match-import-with-multiple-exposings-loose () 63 | (test-import "import Foo ( test1 , test2 )" "Foo" nil)) 64 | 65 | (ert-deftest test-match-import-with-qualifier+multiple-exposings-tight () 66 | (test-import "import Foo (test1,test2) as F" "Foo" "F")) 67 | 68 | (ert-deftest test-match-import-with-qualifier+multiple-exposings-loose () 69 | (test-import 70 | "import Foo ( test1 , test2 ) as F" 71 | "Foo" 72 | "F")) 73 | 74 | (ert-deftest test-all-imported-modules () 75 | (let ((imports (psc-ide-test-example-with-buffer 76 | (lambda () (psc-ide-all-imported-modules))))) 77 | (should (equal (length imports) 10)))) 78 | 79 | (ert-deftest test-moduels-for-qualifier () 80 | (let ((imports (psc-ide-test-example-with-buffer 81 | (lambda () (psc-ide-modules-for-qualifier "P"))))) 82 | (should (equal (length imports) 2)))) 83 | 84 | (ert-deftest test-get-completion-settings () 85 | (psc-ide-test-example-with-buffer 86 | (lambda () 87 | (let* ((command (json-read-from-string (psc-ide-build-completion-command "P.a" nil))) 88 | (params (cdr (assoc 'params command))) 89 | (filters (append (cdr (assoc 'filters params)) nil)) 90 | (search (-some (lambda (filter) 91 | (when (equal "prefix" (cdr (assoc 'filter filter))) 92 | (cdr (assoc 'search (cdr (assoc 'params filter)))))) filters)) 93 | (modules (-some (lambda (filter) 94 | (when (equal "modules" (cdr (assoc 'filter filter))) 95 | (cdr (assoc 'modules (cdr (assoc 'params filter)))))) filters))) 96 | (should (equal search "a")) 97 | (should (equal (length modules) 2)))))) 98 | -------------------------------------------------------------------------------- /test/test-helper.el: -------------------------------------------------------------------------------- 1 | (require 'cl) 2 | (require 'el-mock) 3 | 4 | (add-to-list 'load-path ".") 5 | (load "psc-ide.el") 6 | --------------------------------------------------------------------------------