Skip to content

Commit d10cd4c

Browse files
committed
Refactors options parsing into its own function
1 parent 60f9416 commit d10cd4c

File tree

1 file changed

+19
-10
lines changed
  • packages/pyright-scip/src

1 file changed

+19
-10
lines changed

packages/pyright-scip/src/lib.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,18 @@ function getSymbolTable(doc: scip.Document): Map<string, scip.SymbolInformation>
3131

3232
const packageName = 'scip-python python';
3333
const commentSyntax = '#';
34+
const formatOptionsPrefix = '# format-options:';
3435

35-
export function formatSnapshot(
36-
input: Input,
37-
doc: scip.Document,
38-
externalSymbols: scip.SymbolInformation[] = []
39-
): string {
40-
const out: string[] = [];
41-
const symbolTable = getSymbolTable(doc);
42-
43-
const formatOptionsPrefix = '# format-options:';
36+
function parseOptions(lines: string[]): {
37+
showDocs: boolean;
38+
showRanges: boolean;
39+
} {
4440
const formatOptions = {
4541
showDocs: false,
4642
showRanges: false,
4743
};
4844

49-
for (let line of input.lines) {
45+
for (let line of lines) {
5046
if (!line.startsWith(formatOptionsPrefix)) {
5147
continue;
5248
}
@@ -66,6 +62,17 @@ export function formatSnapshot(
6662
break;
6763
}
6864

65+
return formatOptions;
66+
}
67+
68+
export function formatSnapshot(
69+
input: Input,
70+
doc: scip.Document,
71+
externalSymbols: scip.SymbolInformation[] = []
72+
): string {
73+
const out: string[] = [];
74+
const symbolTable = getSymbolTable(doc);
75+
6976
const externalSymbolTable: Map<string, scip.SymbolInformation> = new Map();
7077
for (let externalSymbol of externalSymbols) {
7178
externalSymbolTable.set(externalSymbol.symbol, externalSymbol);
@@ -74,6 +81,8 @@ export function formatSnapshot(
7481
const enclosingRanges: { range: Range; symbol: string }[] = [];
7582
const symbolsWithDefinitions: Set<string> = new Set();
7683

84+
const formatOptions = parseOptions(input.lines);
85+
7786
for (let occurrence of doc.occurrences) {
7887
const isDefinition = (occurrence.symbol_roles & scip.SymbolRole.Definition) > 0;
7988
if (isDefinition) {

0 commit comments

Comments
 (0)