@@ -60,49 +60,25 @@ local function get_cmake_opts(path)
6060 local options = {}
6161
6262 local file = io.open (path , " r" )
63-
6463 if file then
65- local in_command = false
66-
67- for line in file :lines () do
68- -- Parse 'add_executable' commands
69- local target = line :match (" ^%s*add_executable%s*%(" )
70- if target then
71- in_command = true
72- target = line :match (" (%b())" )
73- target = target :gsub (" [%(%)]" , " " )
74-
75- -- Split the target string by spaces and take the first part
76- target = target :match (" (%S+)" )
77-
78- table.insert (
79- options ,
80- { text = " CMake " .. target , value = target , bau = " cmake" }
81- )
82- elseif in_command then
83- in_command = false
84- end
85-
86- -- Parse 'add_custom_target' commands
87- local custom_target = line :match (" ^%s*add_custom_target%s*%(" )
88- if custom_target then
89- in_command = true
90- custom_target = line :match (" (%b())" )
91- custom_target = custom_target :gsub (" [%(%)]" , " " )
92-
93- -- Split the custom target string by spaces and take the first part
94- custom_target = custom_target :match (" (%S+)" )
64+ local content = file :read (" *all" )
65+ file :close ()
9566
96- table.insert (
97- options ,
98- { text = " CMake " .. custom_target , value = custom_target , bau = " cmake" }
99- )
100- elseif in_command then
101- in_command = false
102- end
67+ -- Parse add_executable entries
68+ for target in content :gmatch (" add_executable%s*%(%s*([%w_]+)" ) do
69+ table.insert (
70+ options ,
71+ { text = " CMake " .. target , value = target , bau = " cmake" }
72+ )
10373 end
10474
105- file :close ()
75+ -- Parse add_custom_target entries
76+ for target in content :gmatch (" add_custom_target%s*%(%s*([%w_]+)" ) do
77+ table.insert (
78+ options ,
79+ { text = " CMake " .. target , value = target , bau = " cmake" }
80+ )
81+ end
10682 end
10783
10884 return options
0 commit comments