« blib/lib/PLS/Parser/Element/Package.pm
↑ Summary
blib/lib/PLS/Parser/Element/VariableStatement.pm »
| 1 | package PLS::Server::Request::Initialized; | ||||||||||
| 2 | |||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 13 | ▶ | use parent 'PLS::Server::Request'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 13 | ▶ | use List::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 13 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 13 | ▶ | use PLS::JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 13 | ▶ | use PLS::Server::Request::Workspace::Configuration; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 13 | ▶ | use PLS::Server::Request::Client::RegisterCapability; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 13 | ▶ | use PLS::Server::Request::Progress; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 13 | ▶ | use PLS::Server::Request::Window::WorkDoneProgress::Create; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 13 | ▶ | use PLS::Server::State; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | =head1 NAME | ||||||||||
| 19 | |||||||||||
| 20 | PLS::Server::Request::Initialized | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | This is a request from the client to the server indicating that it received | ||||||||||
| 25 | the result of the initialize request from the server. | ||||||||||
| 26 | |||||||||||
| 27 | The server sends back some initial requests that it needs to complete initialization. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | sub service | ||||||||||
| 32 | 5 | ▶ | { | ||||||||
|
Subroutine
service: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 33 | 5 | my ($self, $server) = @_; | |||||||||
| 34 | |||||||||||
| 35 | # now that we're initialized, put in a request for our configuration items. | ||||||||||
| 36 | 5 | $server->send_server_request(PLS::Server::Request::Workspace::Configuration->new()); | |||||||||
| 37 | |||||||||||
| 38 | # request that we receive a notification any time configuration changes | ||||||||||
| 39 | 5 | my @capabilities = ({id => 'did-change-configuration', method => 'workspace/didChangeConfiguration'}); | |||||||||
| 40 | |||||||||||
| 41 | # request that we receive a notification every time a file changes, | ||||||||||
| 42 | # so that we can reindex it. | ||||||||||
| 43 | 5 | my $index = PLS::Parser::Index->new(); | |||||||||
| 44 | |||||||||||
| 45 | 5 | ▶ | if (scalar @{$index->workspace_folders}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | { | ||||||||||
| 47 | 5 | push @capabilities, | |||||||||
| 48 | { | ||||||||||
| 49 | id => 'did-change-watched-files', | ||||||||||
| 50 | method => 'workspace/didChangeWatchedFiles', | ||||||||||
| 51 | registerOptions => { | ||||||||||
| 52 | watchers => [ | ||||||||||
| 53 | { | ||||||||||
| 54 | globPattern => '**/*' | ||||||||||
| 55 | } | ||||||||||
| 56 | ] | ||||||||||
| 57 | } | ||||||||||
| 58 | }; | ||||||||||
| 59 | } ## end if (scalar @{$index->workspace_folders...}) | ||||||||||
| 60 | |||||||||||
| 61 | 5 | $server->send_server_request(PLS::Server::Request::Client::RegisterCapability->new(\@capabilities)); | |||||||||
| 62 | |||||||||||
| 63 | # Now is a good time to start indexing files. | ||||||||||
| 64 | 5 | $self->index_files($index, $server); | |||||||||
| 65 | |||||||||||
| 66 | 5 | return; | |||||||||
| 67 | } ## end sub service | ||||||||||
| 68 | |||||||||||
| 69 | sub index_files | ||||||||||
| 70 | 5 | ▶ | { | ||||||||
|
Subroutine
index_files: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||
| 71 | 5 | my ($self, $index, $server) = @_; | |||||||||
| 72 | |||||||||||
| 73 | 5 | ▶ | if ($PLS::Server::State::CLIENT_CAPABILITIES->{window}{workDoneProgress}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | { | ||||||||||
| 75 | 5 | $self->index_files_with_progress($index, $server); | |||||||||
| 76 | } | ||||||||||
| 77 | else | ||||||||||
| 78 | { | ||||||||||
| 79 | 0 | $self->index_files_without_progress($index); | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 5 | return; | |||||||||
| 83 | } ## end sub index_files | ||||||||||
| 84 | |||||||||||
| 85 | sub index_files_without_progress | ||||||||||
| 86 | 0 | ▶ | { | ||||||||
|
Subroutine
index_files_without_progress: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 87 | 0 | my (undef, $index) = @_; | |||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | $index->index_files()->then(sub { Future->wait_all(@_) })->retain(); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 90 | |||||||||||
| 91 | 0 | return; | |||||||||
| 92 | } ## end sub index_files_without_progress | ||||||||||
| 93 | |||||||||||
| 94 | sub index_files_with_progress | ||||||||||
| 95 | 5 | ▶ | { | ||||||||
|
Subroutine
index_files_with_progress: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 96 | 5 | my (undef, $index, $server) = @_; | |||||||||
| 97 | |||||||||||
| 98 | 5 | my $work_done_progress_create = PLS::Server::Request::Window::WorkDoneProgress::Create->new(); | |||||||||
| 99 | 5 | $server->send_server_request($work_done_progress_create); | |||||||||
| 100 | |||||||||||
| 101 | $server->send_server_request( | ||||||||||
| 102 | PLS::Server::Request::Progress->new( | ||||||||||
| 103 | token => $work_done_progress_create->{params}{token}, | ||||||||||
| 104 | 5 | kind => 'begin', | |||||||||
| 105 | title => 'Indexing', | ||||||||||
| 106 | cancellable => PLS::JSON::false, | ||||||||||
| 107 | percentage => 0 | ||||||||||
| 108 | ) | ||||||||||
| 109 | ); | ||||||||||
| 110 | |||||||||||
| 111 | $index->index_files()->then( | ||||||||||
| 112 | 4 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 113 | 4 | my @futures = @_; | |||||||||
| 114 | |||||||||||
| 115 | 4 | my $done = 0; | |||||||||
| 116 | 4 | my $total = scalar @futures; | |||||||||
| 117 | |||||||||||
| 118 | 4 | foreach my $future (@futures) | |||||||||
| 119 | { | ||||||||||
| 120 | $future->then( | ||||||||||
| 121 | 4 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 4 | my ($file) = @_; | |||||||||
| 123 | |||||||||||
| 124 | 4 | ▶ | my $workspace_folder = List::Util::first { path($_)->subsumes($file) } @{$index->workspace_folders}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 125 | 4 | $file = path($file)->relative($workspace_folder); | |||||||||
| 126 | 4 | $done++; | |||||||||
| 127 | $server->send_server_request( | ||||||||||
| 128 | PLS::Server::Request::Progress->new( | ||||||||||
| 129 | token => $work_done_progress_create->{params}{token}, | ||||||||||
| 130 | 4 | kind => 'report', | |||||||||
| 131 | message => "Indexed $file ($done/$total)", | ||||||||||
| 132 | percentage => int($done * 100 / $total) | ||||||||||
| 133 | ) | ||||||||||
| 134 | ); | ||||||||||
| 135 | } | ||||||||||
| 136 | 4 | )->retain(); | |||||||||
| 137 | } ## end foreach my $future (@futures...) | ||||||||||
| 138 | |||||||||||
| 139 | return Future->wait_all(@futures)->then( | ||||||||||
| 140 | 4 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 141 | $server->send_server_request( | ||||||||||
| 142 | PLS::Server::Request::Progress->new( | ||||||||||
| 143 | token => $work_done_progress_create->{params}{token}, | ||||||||||
| 144 | 4 | kind => 'end', | |||||||||
| 145 | message => 'Finished indexing all files' | ||||||||||
| 146 | ) | ||||||||||
| 147 | ); | ||||||||||
| 148 | |||||||||||
| 149 | } | ||||||||||
| 150 | 4 | ); | |||||||||
| 151 | } | ||||||||||
| 152 | 5 | )->retain(); | |||||||||
| 153 | |||||||||||
| 154 | 5 | return; | |||||||||
| 155 | } ## end sub index_files_with_progress | ||||||||||
| 156 | |||||||||||
| 157 | 13 | 1; | |||||||||