コード例 #1
0
ファイル: Fix.php プロジェクト: tsufeki/phpcmplr
 protected function handle($data, PhpCmplr $phpcmplr)
 {
     parent::handle($data, $phpcmplr);
     $container = $phpcmplr->getFile($data->location->path);
     $fixesData = [];
     if ($container !== null) {
         $file = $container->get('file');
         $nearestDiag = null;
         $nearestDistance = 999999;
         /** @var Diagnostic $diag */
         foreach ($container->get('diagnostics')->getDiagnostics() as $diag) {
             // TODO: not only the first range
             $range = $diag->getRanges()[0];
             list($line1, $col1) = $range->getStart()->getLineAndColumn($file);
             list($line2, $col2) = $range->getEnd()->getLineAndColumn($file);
             list($line, $col) = [$data->location->line, $data->location->col];
             if (($line > $line1 || $line == $line1 && $col >= $col1) && ($line < $line2 || $line == $line2 && $col <= $col2)) {
                 $distance = 0;
             } elseif ($line == $line1 && $line == $line2) {
                 $distance = min(abs($col1 - $col), abs($col2 - $col));
             } elseif ($line == $line1) {
                 $distance = $col1 - $col;
             } elseif ($line == $line2) {
                 $distance = $col - $col2;
             } else {
                 continue;
             }
             if ($distance < $nearestDistance) {
                 $nearestDistance = $distance;
                 $nearestDiag = $diag;
             }
         }
         if ($nearestDiag !== null) {
             /** @var FixObject $fix */
             foreach ($nearestDiag->getFixes() as $fix) {
                 $fixData = new \stdClass();
                 $fixData->description = $fix->getDescription();
                 $fixData->chunks = [];
                 /** @var FixChunk $chunk */
                 foreach ($fix->getChunks() as $chunk) {
                     $chunkData = new \stdClass();
                     $chunkData->start = $this->makeLocation($chunk->getRange()->getStart(), $file, true);
                     $chunkData->end = $this->makeLocation($chunk->getRange()->getEnd(), $file, true);
                     $chunkData->replacement = $chunk->getReplacement();
                     $fixData->chunks[] = $chunkData;
                 }
                 $fixesData[] = $fixData;
             }
         }
     }
     $result = new \stdClass();
     $result->fixes = $fixesData;
     return $result;
 }
コード例 #2
0
ファイル: Type.php プロジェクト: tsufeki/phpcmplr
 protected function handle($data, PhpCmplr $phpcmplr)
 {
     parent::handle($data, $phpcmplr);
     $container = $phpcmplr->getFile($data->location->path);
     $type = null;
     if ($container !== null) {
         $file = $container->get('file');
         $offset = $file->getOffset($data->location->line, $data->location->col);
         $type = $container->get('typeinfer')->getType($offset);
     }
     $result = new \stdClass();
     $result->type = $type !== null ? $type->toString() : null;
     return $result;
 }
コード例 #3
0
ファイル: GoTo_.php プロジェクト: tsufeki/phpcmplr
 protected function handle($data, PhpCmplr $phpcmplr)
 {
     parent::handle($data, $phpcmplr);
     $container = $phpcmplr->getFile($data->location->path);
     $gotoData = [];
     if ($container !== null) {
         $file = $container->get('file');
         $offset = $file->getOffset($data->location->line, $data->location->col);
         foreach ($container->get('goto')->getGoToLocations($offset) as $location) {
             $gotoContainer = $phpcmplr->getFile($location->getPath());
             if ($gotoContainer === null) {
                 $gotoContainer = $phpcmplr->addFile($location->getPath(), $container->get('io')->read($location->getPath()));
             }
             $gotoData[] = $this->makeLocation($location, $gotoContainer->get('file'), true);
         }
     }
     $result = new \stdClass();
     $result->goto = $gotoData;
     return $result;
 }
コード例 #4
0
ファイル: Complete.php プロジェクト: tsufeki/phpcmplr
 protected function handle($data, PhpCmplr $phpcmplr)
 {
     parent::handle($data, $phpcmplr);
     $container = $phpcmplr->getFile($data->location->path);
     $completionsData = [];
     if ($container !== null) {
         $file = $container->get('file');
         $offset = $file->getOffset($data->location->line, $data->location->col);
         foreach ($container->get('completer')->complete($offset) as $completion) {
             $data = new \stdClass();
             $data->insertion = $completion->getInsertion();
             $data->display = $completion->getDisplay();
             $data->kind = $completion->getKind();
             $data->type = $completion->getType();
             $data->description = $completion->getDescription();
             $completionsData[] = $data;
         }
     }
     $result = new \stdClass();
     $result->completions = $completionsData;
     return $result;
 }
コード例 #5
0
ファイル: Diagnostics.php プロジェクト: tsufeki/phpcmplr
 protected function handle($data, PhpCmplr $phpcmplr)
 {
     parent::handle($data, $phpcmplr);
     $container = $phpcmplr->getFile($data->path);
     $diagsData = [];
     if ($container !== null) {
         $file = $container->get('file');
         /** @var Diagnostic $diag */
         foreach ($container->get('diagnostics')->getDiagnostics() as $diag) {
             $diagData = new \stdClass();
             // TODO: not only the first range
             $range = $diag->getRanges()[0];
             $diagData->start = $this->makeLocation($range->getStart(), $file);
             $diagData->end = $this->makeLocation($range->getEnd(), $file);
             $diagData->description = $diag->getDescription();
             $diagsData[] = $diagData;
         }
     }
     $result = new \stdClass();
     $result->diagnostics = $diagsData;
     return $result;
 }