Skip to content
代码片段 群组 项目
未验证 提交 6844cb93 编辑于 作者: Dzmitry (Dima) Meshcharakou's avatar Dzmitry (Dima) Meshcharakou 提交者: GitLab
浏览文件

Merge branch 'add-cpp-conantxt-config-file-class' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -9,7 +9,9 @@ module Constants ...@@ -9,7 +9,9 @@ module Constants
# should always appear first before non-lock files. This ordering affects # should always appear first before non-lock files. This ordering affects
# the result of ConfigFileParser#find_config_file_paths_with_class. # the result of ConfigFileParser#find_config_file_paths_with_class.
CONFIG_FILE_CLASSES = [ CONFIG_FILE_CLASSES = [
ConfigFiles::CppConanTxt,
ConfigFiles::GoModules, ConfigFiles::GoModules,
ConfigFiles::JavaGradle,
ConfigFiles::JavaMaven, ConfigFiles::JavaMaven,
ConfigFiles::RubyGemsLock ConfigFiles::RubyGemsLock
].freeze ].freeze
......
# frozen_string_literal: true
module Ai
module Context
module Dependencies
module ConfigFiles
class CppConanTxt < Base
START_SECTION_REGEX = /^\[requires\]/ # Identifies the dependencies section
START_NEXT_SECTION_REGEX = /^\[/
COMMENT_ONLY_REGEX = /^#/
def self.file_name_glob
'conanfile.txt'
end
def self.lang_name
'C++'
end
private
### Example format:
#
# [requires]
# libiconv/1.17
# openssl/3.2.2u # An inline comment
# poco/[>1.0,<1.9]
# # A comment-only line
# zlib/1.2.13#revision1
# boost/1.67.0@conan/stable
#
def extract_libs
libs = []
in_deps_section = false
content.each_line do |line|
line.strip!
next unless line.present?
if START_SECTION_REGEX.match?(line)
in_deps_section = true
elsif in_deps_section && START_NEXT_SECTION_REGEX.match?(line)
break
elsif in_deps_section && !COMMENT_ONLY_REGEX.match?(line)
libs << parse_lib(line)
end
end
libs
end
def parse_lib(line)
name_version, _ = line.split(/@|#/)
name, version = name_version.split('/')
version&.gsub!(/\[|\]/, '') # Version could be a range, e.g. [>1.0,<1.9]
Lib.new(name: name, version: version)
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ai::Context::Dependencies::ConfigFiles::CppConanTxt, feature_category: :code_suggestions do
it 'returns the expected language value' do
expect(described_class.lang).to eq('cpp')
end
it_behaves_like 'parsing a valid dependency config file' do
let(:config_file_content) do
<<~CONTENT
[requires]
libiconv/1.17
openssl/3.2.2u # An inline comment
poco/[>1.0,<1.9]
# A comment-only line
zlib/1.2.13#revision1
boost/1.67.0@conan/stable
[generators]
cmake_find_package_multi
[options]
pkg/openssl:shared=False
CONTENT
end
let(:expected_formatted_lib_names) do
[
'libiconv (1.17)',
'openssl (3.2.2u)',
'poco (>1.0,<1.9)',
'zlib (1.2.13)',
'boost (1.67.0)'
]
end
end
it_behaves_like 'parsing an invalid dependency config file'
describe '.matches?' do
using RSpec::Parameterized::TableSyntax
where(:path, :matches) do
'conanfile.txt' | true
'dir/conanfile.txt' | true
'dir/subdir/conanfile.txt' | true
'dir/conanfile' | false
'xconanfile.txt' | false
'Conanfile.txt' | false
'conanfile_txt' | false
'conanfile' | false
end
with_them do
it 'matches the file name glob pattern at various directory levels' do
expect(described_class.matches?(path)).to eq(matches)
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册