11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/nvim-mcp-server/tools/get_project_buffers_tool.rb', line 11
def call(project_name:)
socket_path = "/tmp/nvim-#{project_name}.sock"
log(:info, "Getting buffers for project #{project_name} using socket #{socket_path}")
result = {
status: "success",
project_name: project_name,
socket_path: socket_path,
files: []
}
begin
unless File.exist?(socket_path)
result[:status] = "error"
result[:message] = "Neovim socket not found: #{socket_path}"
return result
end
client = Neovim.attach_unix(socket_path)
all_buffers = client.list_bufs
project_files = []
all_buffers.each do |buffer|
buffer_name = buffer.name
next if buffer_name.nil? || buffer_name.empty?
path_parts = buffer_name.split(File::SEPARATOR)
if path_parts.include?(project_name)
project_files << buffer_name
end
rescue => e
log(:error, "Error processing buffer: #{e.message}")
next
end
result[:files] = project_files.sort
client.shutdown
rescue => e
log(:error, "Error connecting to Neovim using socket #{socket_path}: #{e.message}")
result[:status] = "error"
result[:message] = e.message
result[:files] = []
end
result
end
|