Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
build/
vscode-mozuku/data/
vscode-mozuku/out/
vscode-mozuku/bin/
vscode-mozuku/metadata.json
dist/
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ MoZuku は、MeCab・CaboCha を活用した日本語文章の解析・校正を
- CaboCha (オプション : 係り受け解析 [WIP] 用)
- CURL
- tree-sitter CLI (ビルド時)

## ビルドとインストール

```sh
cmake -S mozuku-lsp -B mozuku-lsp/build -DCMAKE_BUILD_TYPE=Release
cmake --build mozuku-lsp/build
cmake --install mozuku-lsp/build --prefix ~/.local # 環境によっては sudo が必要です
```

`cmake --install` の出力先は GNUInstallDirs に従い、通常は `<prefix>/bin/mozuku-lsp` です。VS Code 拡張と Vim/Neovim プラグインは、`PATH` と標準的なインストール先、開発中の `build/install` を自動で探索します。
19 changes: 4 additions & 15 deletions mozuku-lsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if(POLICY CMP0177)
cmake_policy(SET CMP0177 NEW)
endif()

include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -178,21 +180,8 @@ message(STATUS " MeCab: ${MECAB_FOUND}")
message(STATUS " CaboCha: ${CABOCHA_FOUND}")
message(STATUS " CURL: ${CURL_FOUND}")

set(VSCODE_EXTENSION_DIR "${CMAKE_SOURCE_DIR}/../vscode-mozuku")

install(TARGETS mozuku-lsp
RUNTIME DESTINATION "${VSCODE_EXTENSION_DIR}/bin"
)

install(TARGETS mozuku-lsp
RUNTIME DESTINATION bin)


add_custom_target(package-extension
COMMAND ${CMAKE_COMMAND} --build . --target install
COMMENT "VS Code拡張をLSPサーバーと共にパッケージ化中 (システムライブラリが必要) "
DEPENDS mozuku-lsp
)
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

message(STATUS "VS Code拡張のパッケージ先: ${VSCODE_EXTENSION_DIR}")
message(STATUS "mozuku-lsp は 'cmake --install' で ${CMAKE_INSTALL_BINDIR} にインストールされます")
message(STATUS "注意: ターゲットシステムにMeCab/CaboCha/CURLライブラリのインストールが必要です")
2 changes: 1 addition & 1 deletion vim-mozuku/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# vim-mozuku

MoZuku LSP を Vim/Neovim で使うための軽量プラグインです。`vim-mozuku/` を runtimepath に追加することで有効化できます。
MoZuku LSP を Vim/Neovim で使うための軽量プラグインです。`vim-mozuku/` を runtimepath に追加することで有効化できます。既定では `mozuku-lsp` を `PATH`、標準的なインストール先、開発中の `build/install` から探索します。
119 changes: 116 additions & 3 deletions vim-mozuku/autoload/mozuku.vim
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,94 @@ function! s:capitalize(word) abort
return toupper(strpart(a:word, 0, 1)) . strpart(a:word, 1)
endfunction

function! s:path_has_sep(path) abort
return a:path =~# '[/\\]'
endfunction

function! s:is_windows() abort
return has('win32') || has('win64')
endfunction

function! s:exe_name(command_name) abort
if s:is_windows() && a:command_name !~? '\.exe$'
return a:command_name . '.exe'
endif
return a:command_name
endfunction

function! s:add_unique(list, value) abort
if empty(a:value)
return
endif
if index(a:list, a:value) < 0
call add(a:list, a:value)
endif
endfunction

function! s:repo_root() abort
return fnamemodify(expand('<sfile>:p'), ':h:h:h')
endfunction

function! s:resolve_explicit_path(path_value) abort
if empty(a:path_value)
return ''
endif
return fnamemodify(a:path_value, ':p')
endfunction

function! s:command_candidates(command_name) abort
let l:candidates = []
if empty(a:command_name)
return l:candidates
endif

let l:exe = s:exe_name(a:command_name)

for l:name in [a:command_name, l:exe]
let l:resolved = exepath(l:name)
if !empty(l:resolved)
call s:add_unique(l:candidates, l:resolved)
endif
endfor

if exists('$HOME')
call s:add_unique(l:candidates, expand('~/.local/bin/' . l:exe))
call s:add_unique(l:candidates, expand('~/bin/' . l:exe))
endif

if has('macunix')
for l:dir in ['/usr/local/bin', '/usr/bin', '/opt/homebrew/bin', '/opt/local/bin']
call s:add_unique(l:candidates, l:dir . '/' . l:exe)
endfor
elseif has('unix')
for l:dir in ['/usr/local/bin', '/usr/bin']
call s:add_unique(l:candidates, l:dir . '/' . l:exe)
endfor
endif

if s:is_windows()
for l:base in [expand('$LOCALAPPDATA'), expand('$ProgramFiles'), expand('$ProgramFiles(x86)')]
if empty(l:base)
continue
endif
for l:name in ['MoZuku', 'mozuku-lsp']
call s:add_unique(l:candidates, l:base . '/' . l:name . '/bin/' . l:exe)
endfor
endfor
endif

let l:repo_root = s:repo_root()
call s:add_unique(l:candidates, l:repo_root . '/build/install/bin/' . l:exe)
call s:add_unique(l:candidates, l:repo_root . '/build/' . l:exe)
call s:add_unique(l:candidates, l:repo_root . '/mozuku-lsp/build/install/bin/' . l:exe)
call s:add_unique(l:candidates, l:repo_root . '/mozuku-lsp/build/' . l:exe)

return l:candidates
endfunction

function! mozuku#config() abort
return {
\ 'server_path': g:mozuku_server_path,
\ 'server_path': mozuku#server_cmd(),
\ 'init_options': mozuku#build_init_options(),
\ }
endfunction
Expand Down Expand Up @@ -261,9 +346,37 @@ endfunction

function! mozuku#server_cmd() abort
if type(g:mozuku_server_path) == v:t_list
return g:mozuku_server_path
return copy(g:mozuku_server_path)
endif

let l:configured = trim(g:mozuku_server_path)
if !empty(l:configured) && s:path_has_sep(l:configured)
return [s:resolve_explicit_path(l:configured)]
endif

let l:env = exists('$MOZUKU_LSP') ? trim($MOZUKU_LSP) : ''
if !empty(l:env) && s:path_has_sep(l:env)
return [s:resolve_explicit_path(l:env)]
endif

for l:command_name in [l:configured, l:env, 'mozuku-lsp']
if empty(l:command_name)
continue
endif
for l:candidate in s:command_candidates(l:command_name)
if executable(l:candidate)
return [fnamemodify(l:candidate, ':p')]
endif
endfor
endfor

if !empty(l:configured)
return [l:configured]
endif
if !empty(l:env)
return [l:env]
endif
return [g:mozuku_server_path]
return ['mozuku-lsp']
endfunction

function! mozuku#vim_on_comment(server, payload) abort
Expand Down
2 changes: 2 additions & 0 deletions vscode-mozuku/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Visual Studio Code 拡張機能 MoZuku は、日本語テキストに対して MeCab と CaboCha を使用したセマンティック解析と診断を提供する日本語言語サーバーです。

既定では `mozuku-lsp` コマンド、`PATH`、標準的なインストール先を探索して起動します。ローカルでビルドする場合は、`mozuku-lsp` を `cmake --install` で `bin` 配下に配置するか、`mozuku.serverPath` で明示してください。

## LICENSE

このプロジェクトと実装は AGPL-3.0 ライセンスの下でライセンスされています。詳細については、[LICENSE](./LICENSE) ファイルを参照してください。
81 changes: 34 additions & 47 deletions vscode-mozuku/build-lsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const { execFileSync } = require("child_process");

const isWindows = process.platform === "win32";
const isLinux = process.platform === "linux";
Expand Down Expand Up @@ -43,39 +43,36 @@ function ensureDir(dirPath) {
}
}

function buildMoZuKuBinary(lspSourceDir) {
function runCMake(args, cwd) {
execFileSync("cmake", args, {
stdio: "inherit",
cwd,
});
}

function buildMoZuKuBinary(lspSourceDir, installPrefix) {
log("Building LSP server...");

try {
// Change to LSP source directory
process.chdir(lspSourceDir);

// Configure and build
if (!fs.existsSync("build")) {
if (!fs.existsSync(path.join(lspSourceDir, "build"))) {
log("Creating build directory...");
fs.mkdirSync("build");
fs.mkdirSync(path.join(lspSourceDir, "build"), { recursive: true });
}

// Configure CMake
log("Configuring with CMake...");
execSync("cmake -B build -DCMAKE_BUILD_TYPE=Release", {
stdio: "inherit",
cwd: lspSourceDir,
});
runCMake(["-B", "build", "-DCMAKE_BUILD_TYPE=Release"], lspSourceDir);

// Build the project
log("Building with CMake...");
execSync("cmake --build build -j 4", {
stdio: "inherit",
cwd: lspSourceDir,
});

// Package extension using CMake install target
log("Packaging extension with CMake install target...");
execSync("cmake --build build --target package-extension", {
stdio: "inherit",
cwd: lspSourceDir,
});
runCMake(
["--build", "build", "--config", "Release", "--parallel", "4"],
lspSourceDir,
);

log(`Installing with CMake into: ${installPrefix}`);
runCMake(
["--install", "build", "--config", "Release", "--prefix", installPrefix],
lspSourceDir,
);
} catch (error) {
log(`Build failed: ${error.message}`);
throw error;
Expand Down Expand Up @@ -107,6 +104,7 @@ function buildForCurrentPlatform() {

const lspSourceDir = path.join(__dirname, "..", "mozuku-lsp");
const binDir = path.join(__dirname, "bin");
const installPrefix = __dirname;

// Clean previous build
if (fs.existsSync(binDir)) {
Expand All @@ -119,32 +117,21 @@ function buildForCurrentPlatform() {

// Nixによるビルド成果物がない場合はビルドを行う
if (fs.existsSync(path.join(__dirname, "..", "result", "bin"))) {

const exeName =
currentTarget.platform === "win32" ? "mozuku-lsp.exe" : "mozuku-lsp";
const nixExecutable = path.join(__dirname, "..", "result", "bin", exeName);
const targetExecutable = path.join(binDir, exeName);
log(`Copying Nix executable: ${nixExecutable} -> ${targetExecutable}`);
fs.copyFileSync(nixExecutable, targetExecutable);
} else {
buildMoZuKuBinary(lspSourceDir)
buildMoZuKuBinary(lspSourceDir, installPrefix);
}

// Copy the built executable
const exeName = currentTarget.platform === "win32"
? "mozuku-lsp.exe"
: "mozuku-lsp";
const builtExecutable = path.join(lspSourceDir, "build", exeName);
const exeName =
currentTarget.platform === "win32" ? "mozuku-lsp.exe" : "mozuku-lsp";
const targetExecutable = path.join(binDir, exeName);

if (!fs.existsSync(builtExecutable)) {
// Try alternative build location
const altExecutable = path.join(lspSourceDir, exeName);
if (fs.existsSync(altExecutable)) {
log(`Copying executable from alternative location: ${altExecutable}`);
fs.copyFileSync(altExecutable, targetExecutable);
} else {
throw new Error(
`Built executable not found at: ${builtExecutable} or ${altExecutable}`,
);
}
} else {
log(`Copying executable: ${builtExecutable} -> ${targetExecutable}`);
fs.copyFileSync(builtExecutable, targetExecutable);
if (!fs.existsSync(targetExecutable)) {
throw new Error(`Installed executable not found at: ${targetExecutable}`);
}

// Make executable on Unix-like systems
Expand Down
Loading