cmake: install M2-language-server script#4453
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Oh, I hadn't seen the this script. Aside from cmake conventions, I don't think this script is the right way to go because it doesn't work if M2 isn't on the path or if you have multiple M2's on different paths, e.g. if I'm running M2 from a build directory I might not want the M2-language-server from brew to be used.
I would suggest one two options:
- move this script to the
Macaulay2/bindirectory and adjust it like the M2 script to run the correct M2-binary or just call./M2in the same directory, then move theinstallcall tobin/CMakeFiles.txtand remove theCOPYcall. - better yet, add this invocation as an argument to M2, e.g.
startup.m2should parse--LSPand just run this, with no extra files involved.
|
Ooh, yeah, I like option 1. I'm hesitant about option 2. In particular, I foresee adding command-line options to |
|
You could have a phase 0 check that if |
The M2-language-server script previously called a bare M2, so it relied entirely on $PATH and broke when M2 wasn't on the path or when multiple M2 installations existed. Resolve M2 relative to the script's own location instead: an LSP client launches the server by path (typically the absolute install path), and the M2 wrapper sits beside the script in bindir, so $(dirname "$0")/M2 reliably finds the matching M2 regardless of $PATH or cwd. Sibling resolution via $(dirname "$0") works whenever $0 contains a slash, which covers the normal installed case. When no sibling M2 is found -- e.g. running the script from the source directory (packages/LanguageServer), or invoking it by bare name resolved through PATH (where dirname yields ".") -- fall back to a bare M2 on PATH. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
I updated the script to check first for the existence of a "sibling" I decided to keep everything in the |
I inadvertently added it when adding the language server. It must have snuck in from an earlier draft!
|
I would like the lines added to packages/CMakeFiles.txt in the previous PR to be removed. Further, since humans would not need to run You can make this a separate debian package / brew formula which can be selectively installed. |
|
I thought I removed the stray newline? I don't understand why this shouldn't be on the PATH. Even if humans won't run it directly, editors certainly will. |
| file(COPY LanguageServer/M2-language-server | ||
| DESTINATION ${M2_DIST_PREFIX}/${M2_INSTALL_BINDIR}) | ||
|
|
||
| install(PROGRAMS LanguageServer/M2-language-server | ||
| DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| COMPONENT ALL) |
There was a problem hiding this comment.
These lines should not be here. This file is for packages only.
I still think adding --language-server option in startup.m2 is the best option, but another alternative is adding a target under Macaulay2/editors/language-server. e.g. prism and generate-symbols.m2 interact with the Style package, but we don't write those targets in packages/CMakeFiles.txt just because Style is in this directory.
There was a problem hiding this comment.
But the language server is a package... It's an unusual package in that it has an accompanying script and folks would rarely if ever ever load it by hand, but all the related code is here in the packages directory.
I'd rather avoid touching startup.m2. Keeping the script in the package's auxiliary directory keeps everything close together, and also doesn't require recompiling M2.
I think the comparison to prism actually supports the current proprosal. For prism, the build system targets live in the editors directory since that's where the source code is even though the files get installed alongside the packages. Same idea here -- the source code is in packages but we're installing it alongside the binary.
There was a problem hiding this comment.
For prism, the build system targets live in the
editorsdirectory since that's where the source code is even though the files get installed alongside the packages.
The template is there but the file is generated by generateSymbols which lives in the Style package, so these two seem contradictory:
- we should keep the script in the package's aux directory to keep things together
- we should keep the script in the directory where it gets installed
Either move it to Macaulay2/bin if it needs to be installed on path next to M2 and M2-binary (the main file could live in bin and have a symlink from the aux directory), or to Macaulay2/editors/language-server and put the path in editor configuration.
I believe |
That's where binaries that M2 would call should live. A language server should be on |
I just installed M2 on my new MacBook and noticed that the language server script was missing!
The homebrew package uses the cmake build, and (as usual), I don't really understand cmake that well and didn't realize we needed an additional
install(). I figured that just copying it tousr-distlike we do for the autotools build was sufficient. Nope!AI Disclosure
Claude figured out what was missing and added the fix.