Skip to content

Commit 0ca44f5

Browse files
committed
sourcegraph#86 - Adds support for format-options in snapshot inputs
1 parent 487edae commit 0ca44f5

File tree

1 file changed

+30
-3
lines changed
  • packages/pyright-scip/src

1 file changed

+30
-3
lines changed

packages/pyright-scip/src/lib.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ export function formatSnapshot(
4040
const out: string[] = [];
4141
const symbolTable = getSymbolTable(doc);
4242

43+
const formatOptionsPrefix = '# format-options:';
44+
const formatOptions = {
45+
showDocs: false,
46+
showRanges: false,
47+
};
48+
49+
for (let line of input.lines) {
50+
if (!line.startsWith(formatOptionsPrefix)) {
51+
continue;
52+
}
53+
54+
const options = line.slice(formatOptionsPrefix.length).trim().split(',');
55+
56+
for (let option of options) {
57+
const optionName = option.trim();
58+
59+
if (!(optionName in formatOptions)) {
60+
throw new Error(`Invalid format option: ${optionName}`);
61+
}
62+
63+
formatOptions[optionName as keyof typeof formatOptions] = true;
64+
}
65+
66+
break;
67+
}
68+
4369
const externalSymbolTable: Map<string, scip.SymbolInformation> = new Map();
4470
for (let externalSymbol of externalSymbols) {
4571
externalSymbolTable.set(externalSymbol.symbol, externalSymbol);
@@ -75,6 +101,10 @@ export function formatSnapshot(
75101
}
76102

77103
const pushOneDoc = (docs: string[], external: boolean) => {
104+
if (!formatOptions.showDocs) {
105+
return;
106+
}
107+
78108
for (const documentation of docs) {
79109
for (const [idx, line] of documentation.split('\n').entries()) {
80110
out.push(prefix);
@@ -189,9 +219,6 @@ export function formatSnapshot(
189219
const isDefinition = (occurrence.symbol_roles & scip.SymbolRole.Definition) > 0;
190220
out.push(isDefinition ? 'definition' : 'reference');
191221
out.push(' ');
192-
if (occurrence.enclosing_range.length) {
193-
out.push('<enclosing ' + occurrence.enclosing_range.join(', ') + '>');
194-
}
195222
const symbol = occurrence.symbol.startsWith(packageName)
196223
? occurrence.symbol.slice(packageName.length)
197224
: occurrence.symbol;

0 commit comments

Comments
 (0)