Commit b6b9c976 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'id-lsif-fetch-hovers' into 'master'

Code Nav Poc: Extend LSIF info with hover data

See merge request gitlab-org/gitlab!23682
parents 09b472fe 177a58d3
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Projects module Projects
class LsifDataService class LsifDataService
attr_reader :file, :project, :path, :commit_id, attr_reader :file, :project, :path, :commit_id,
:docs, :doc_ranges, :ranges, :def_refs :docs, :doc_ranges, :ranges, :def_refs, :hover_refs
CACHE_EXPIRE_IN = 1.hour CACHE_EXPIRE_IN = 1.hour
...@@ -26,7 +26,8 @@ module Projects ...@@ -26,7 +26,8 @@ module Projects
end_line: line_data.last, end_line: line_data.last,
start_char: column_data.first, start_char: column_data.first,
end_char: column_data.last, end_char: column_data.last,
definition_url: definition_url_for(def_refs[ref_id]) definition_url: definition_url_for(def_refs[ref_id]),
hover: highlighted_hover(hover_refs[ref_id])
} }
end end
end end
...@@ -54,6 +55,7 @@ module Projects ...@@ -54,6 +55,7 @@ module Projects
@doc_ranges = data['doc_ranges'] @doc_ranges = data['doc_ranges']
@ranges = data['ranges'] @ranges = data['ranges']
@def_refs = data['def_refs'] @def_refs = data['def_refs']
@hover_refs = data['hover_refs']
end end
def doc_id def doc_id
...@@ -86,5 +88,16 @@ module Projects ...@@ -86,5 +88,16 @@ module Projects
Gitlab::Routing.url_helpers.project_blob_path(project, definition_ref_path, anchor: line_anchor) Gitlab::Routing.url_helpers.project_blob_path(project, definition_ref_path, anchor: line_anchor)
end end
def highlighted_hover(hovers)
hovers&.map do |hover|
# Documentation for a method which is added as comments on top of the method
# is stored as a raw string value in LSIF file
next { value: hover } unless hover.is_a?(Hash)
value = Gitlab::Highlight.highlight(nil, hover['value'], language: hover['language'])
{ language: hover['language'], value: value }
end
end
end end
end end
...@@ -61,7 +61,11 @@ describe API::LsifData do ...@@ -61,7 +61,11 @@ describe API::LsifData do
'end_line' => 8, 'end_line' => 8,
'start_char' => 13, 'start_char' => 13,
'start_line' => 8, 'start_line' => 8,
'definition_url' => project_blob_path(project, "#{commit.id}/morestrings/reverse.go", anchor: 'L5') 'definition_url' => project_blob_path(project, "#{commit.id}/morestrings/reverse.go", anchor: 'L5'),
'hover' => [{
'language' => 'go',
'value' => Gitlab::Highlight.highlight(nil, 'func Func2(i int) string', language: 'go')
}]
}) })
end end
......
...@@ -12,6 +12,10 @@ describe Projects::LsifDataService do ...@@ -12,6 +12,10 @@ describe Projects::LsifDataService do
let(:service) { described_class.new(artifact.file, project, params) } let(:service) { described_class.new(artifact.file, project, params) }
describe '#execute' do describe '#execute' do
def highlighted_value(value)
[{ language: 'go', value: Gitlab::Highlight.highlight(nil, value, language: 'go') }]
end
context 'fetched lsif file', :use_clean_rails_memory_store_caching do context 'fetched lsif file', :use_clean_rails_memory_store_caching do
it 'is cached' do it 'is cached' do
service.execute service.execute
...@@ -32,42 +36,48 @@ describe Projects::LsifDataService do ...@@ -32,42 +36,48 @@ describe Projects::LsifDataService do
end_line: 6, end_line: 6,
start_char: 5, start_char: 5,
start_line: 6, start_line: 6,
definition_url: "#{path_prefix}/main.go#L7" definition_url: "#{path_prefix}/main.go#L7",
hover: highlighted_value('func main()')
}, },
{ {
end_char: 36, end_char: 36,
end_line: 3, end_line: 3,
start_char: 1, start_char: 1,
start_line: 3, start_line: 3,
definition_url: "#{path_prefix}/main.go#L4" definition_url: "#{path_prefix}/main.go#L4",
hover: highlighted_value('package "github.com/user/hello/morestrings" ("github.com/user/hello/morestrings")')
}, },
{ {
end_char: 12, end_char: 12,
end_line: 7, end_line: 7,
start_char: 1, start_char: 1,
start_line: 7, start_line: 7,
definition_url: "#{path_prefix}/main.go#L4" definition_url: "#{path_prefix}/main.go#L4",
hover: highlighted_value('package "github.com/user/hello/morestrings" ("github.com/user/hello/morestrings")')
}, },
{ {
end_char: 20, end_char: 20,
end_line: 7, end_line: 7,
start_char: 13, start_char: 13,
start_line: 7, start_line: 7,
definition_url: "#{path_prefix}/morestrings/reverse.go#L11" definition_url: "#{path_prefix}/morestrings/reverse.go#L11",
hover: highlighted_value('func Reverse(s string) string') + [{ value: "This method reverses a string \n\n" }]
}, },
{ {
end_char: 12, end_char: 12,
end_line: 8, end_line: 8,
start_char: 1, start_char: 1,
start_line: 8, start_line: 8,
definition_url: "#{path_prefix}/main.go#L4" definition_url: "#{path_prefix}/main.go#L4",
hover: highlighted_value('package "github.com/user/hello/morestrings" ("github.com/user/hello/morestrings")')
}, },
{ {
end_char: 18, end_char: 18,
end_line: 8, end_line: 8,
start_char: 13, start_char: 13,
start_line: 8, start_line: 8,
definition_url: "#{path_prefix}/morestrings/reverse.go#L5" definition_url: "#{path_prefix}/morestrings/reverse.go#L5",
hover: highlighted_value('func Func2(i int) string')
} }
]) ])
end end
...@@ -82,7 +92,8 @@ describe Projects::LsifDataService do ...@@ -82,7 +92,8 @@ describe Projects::LsifDataService do
end_line: 11, end_line: 11,
start_char: 1, start_char: 1,
start_line: 11, start_line: 11,
definition_url: "/#{project.full_path}/-/blob/#{commit_id}/morestrings/reverse.go#L12" definition_url: "/#{project.full_path}/-/blob/#{commit_id}/morestrings/reverse.go#L12",
hover: highlighted_value('var a string')
}) })
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment