From e46e93920c81272ef2dc912524916db460ad6bd9 Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Sat, 12 Oct 2024 20:45:31 -0400 Subject: [PATCH 1/3] add emitter cli arguments --- bin/lsif-php | 19 +++++++++++++++++-- src/Protocol/Emitter.php | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bin/lsif-php b/bin/lsif-php index c121864..501ee21 100755 --- a/bin/lsif-php +++ b/bin/lsif-php @@ -10,7 +10,7 @@ use LsifPhp\Indexer\Indexer; use LsifPhp\Protocol\Emitter; use LsifPhp\Protocol\ToolInfo; -$options = \getopt('h', ['help', 'memory-limit:']); +$options = \getopt('h', ['help', 'memory-limit:', 'id:', 'filename:']); if ($options === false) { echo "Cannot parse options.\n"; exit(1); @@ -36,11 +36,26 @@ if (\ini_set('memory_limit', $memoryLimit) === false) { exit(1); } +$id = intval($options['id'] ?? '0'); +if ($id < 0) { + echo "Invalid id.\n"; + exit(1); +} + +$filename = $options['filename'] ?? 'dump.lsif'; +if (!\is_string($filename) || \substr($filename, -5) !== '.lsif') { + echo "Invalid filename. Must be a file ending with .lsif\n"; + exit(1); +} + $projectRoot = \getcwd(); $toolInfo = new ToolInfo('lsif-php', '0.0.6', \array_splice($argv, 1)); $git = new Git(); -$emitter = new Emitter(); +$emitter = new Emitter( + filename: $filename, + id: $id, +); $indexer = new Indexer($projectRoot, $emitter, $toolInfo, $git->version()); $indexer->index(); $emitter->write(); diff --git a/src/Protocol/Emitter.php b/src/Protocol/Emitter.php index aaed776..bdd2251 100644 --- a/src/Protocol/Emitter.php +++ b/src/Protocol/Emitter.php @@ -18,9 +18,9 @@ final class Emitter private FileWriter $writer; - public function __construct(string $filename = 'dump.lsif') + public function __construct(string $filename = 'dump.lsif', int $id = 0) { - $this->id = 0; + $this->id = $id; $this->writer = new FileWriter($filename); } From f2c5abc9c19b01451f4f0a891ce889a3cc8c94ff Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Sat, 16 Nov 2024 13:07:39 -0500 Subject: [PATCH 2/3] improve element id start expectations --- bin/lsif-php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/lsif-php b/bin/lsif-php index 501ee21..d3cde85 100755 --- a/bin/lsif-php +++ b/bin/lsif-php @@ -36,9 +36,9 @@ if (\ini_set('memory_limit', $memoryLimit) === false) { exit(1); } -$id = intval($options['id'] ?? '0'); +$id = intval($options['id'] ?? '1') - 1; if ($id < 0) { - echo "Invalid id.\n"; + echo "Invalid start element ID.\n"; exit(1); } From 881dc2fc78f72bc667d84c5f06a189eb0556b5e0 Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Sat, 16 Nov 2024 13:07:49 -0500 Subject: [PATCH 3/3] added new options to help command --- bin/lsif-php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/lsif-php b/bin/lsif-php index d3cde85..d2b347b 100755 --- a/bin/lsif-php +++ b/bin/lsif-php @@ -22,6 +22,8 @@ if (isset($options['h']) || isset($options['help'])) { echo "Options:\n"; echo " -h --help display this help and exit\n"; echo " --memory-limit=\"1G\" memory limit\n"; + echo " --id=1 the starting element ID to start from\n"; + echo " --filename=dump.lsif the name of the file output\n"; exit(0); }