Skip to content

Commit

Permalink
feat: implemented provideFoldingRanges
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 9, 2022
1 parent ddde114 commit dd083d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/monaco/code2monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,13 @@ export function asColorPresentation(item: vscode.ColorPresentation): monaco.lang
additionalTextEdits: item.additionalTextEdits ? item.additionalTextEdits.map(asTextEdit) : undefined,
};
}

export function asFoldingRange(item: vscode.FoldingRange): monaco.languages.FoldingRange {
return {
start: item.startLine,
end: item.endLine,
kind: {
value: item.kind ?? '',
},
};
}
11 changes: 11 additions & 0 deletions src/monaco/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
}
},
}),
monaco.languages.registerFoldingRangeProvider(lang, {
provideFoldingRanges: async (model) => {
const document = getTextDocument(model);
if (document) {
const codeResult = await ds.getFoldingRanges(document);
if (codeResult) {
return codeResult.map(code2monaco.asFoldingRange);
}
}
},
}),
);

return ls;
Expand Down

0 comments on commit dd083d3

Please sign in to comment.