diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
commit | 2c89e169769ead722394a79ed67fcd08e96863dd (patch) | |
tree | 0dadb576846c484475b895f75fab41f71cdb952e /app/services/projects/lsif_data_service.rb | |
parent | bd497e352ebd279536ae11855871162e82a3f88c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/projects/lsif_data_service.rb')
-rw-r--r-- | app/services/projects/lsif_data_service.rb | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/app/services/projects/lsif_data_service.rb b/app/services/projects/lsif_data_service.rb index 00103f364bf..1282a0736e7 100644 --- a/app/services/projects/lsif_data_service.rb +++ b/app/services/projects/lsif_data_service.rb @@ -2,7 +2,8 @@ module Projects class LsifDataService - attr_reader :file, :project, :path, :commit_id + attr_reader :file, :project, :path, :commit_id, + :docs, :doc_ranges, :ranges, :def_refs CACHE_EXPIRE_IN = 1.hour @@ -14,19 +15,18 @@ module Projects end def execute - docs, doc_ranges, ranges = - fetch_data.values_at('docs', 'doc_ranges', 'ranges') - - doc_id = doc_id_from(docs) + fetch_data! doc_ranges[doc_id]&.map do |range_id| - line_data, column_data = ranges[range_id]['loc'] + location, ref_id = ranges[range_id].values_at('loc', 'ref_id') + line_data, column_data = location { start_line: line_data.first, end_line: line_data.last, start_char: column_data.first, - end_char: column_data.last + end_char: column_data.last, + definition_url: definition_url_for(def_refs[ref_id]) } end end @@ -47,8 +47,17 @@ module Projects end end - def doc_id_from(docs) - docs.reduce(nil) do |doc_id, (id, doc_path)| + def fetch_data! + data = fetch_data + + @docs = data['docs'] + @doc_ranges = data['doc_ranges'] + @ranges = data['ranges'] + @def_refs = data['def_refs'] + end + + def doc_id + @doc_id ||= docs.reduce(nil) do |doc_id, (id, doc_path)| next doc_id unless doc_path =~ /#{path}$/ if doc_id.nil? || docs[doc_id].size > doc_path.size @@ -58,5 +67,24 @@ module Projects doc_id end end + + def dir_absolute_path + @dir_absolute_path ||= docs[doc_id]&.delete_suffix(path) + end + + def definition_url_for(ref_id) + return unless range = ranges[ref_id] + + def_doc_id, location = range.values_at('doc_id', 'loc') + localized_doc_url = docs[def_doc_id].delete_prefix(dir_absolute_path) + + # location is stored as [[start_line, end_line], [start_char, end_char]] + start_line = location.first.first + + line_anchor = "L#{start_line + 1}" + definition_ref_path = [commit_id, localized_doc_url].join('/') + + Gitlab::Routing.url_helpers.project_blob_path(project, definition_ref_path, anchor: line_anchor) + end end end |