mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds foldingrangeprovider
This commit is contained in:
parent
a521c34334
commit
1899118b0d
@ -1,8 +1,3 @@
|
||||
{
|
||||
"folding": {
|
||||
"markers": {
|
||||
"start": "^(Untracked files)|((Unstaged|Staged) changes)|(Stashes)|(Recent commits)",
|
||||
"end": "^\\.$"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { workspace, extensions, commands, ExtensionContext, Disposable } from 'vscode';
|
||||
import { workspace, extensions, commands, ExtensionContext, Disposable, languages } from 'vscode';
|
||||
import ContentProvider from './contentProvider';
|
||||
import { GitExtension, API } from './typings/git';
|
||||
import { pushing } from './commands/pushingCommands';
|
||||
@ -10,6 +10,7 @@ import { MagitRepository } from './models/magitRepository';
|
||||
import { magitCommit } from './commands/commitCommands';
|
||||
import { magitStage, magitStageAll } from './commands/stagingCommands';
|
||||
import { saveClose } from './commands/macros';
|
||||
import FoldingRangeProvider from './foldingRangeProvider';
|
||||
|
||||
export const magitRepositories: { [id: string]: MagitRepository } = {};
|
||||
|
||||
@ -29,13 +30,15 @@ export function activate(context: ExtensionContext) {
|
||||
// });
|
||||
gitApi = gitExtension.getAPI(1);
|
||||
|
||||
const provider = new ContentProvider();
|
||||
const contentProvider = new ContentProvider();
|
||||
const foldingRangeProvider = new FoldingRangeProvider();
|
||||
|
||||
const providerRegistrations = Disposable.from(
|
||||
workspace.registerTextDocumentContentProvider(ContentProvider.scheme, provider)
|
||||
workspace.registerTextDocumentContentProvider(ContentProvider.scheme, contentProvider),
|
||||
languages.registerFoldingRangeProvider(FoldingRangeProvider.scheme, foldingRangeProvider)
|
||||
);
|
||||
context.subscriptions.push(
|
||||
provider,
|
||||
contentProvider,
|
||||
providerRegistrations,
|
||||
);
|
||||
|
||||
|
43
src/foldingRangeProvider.ts
Normal file
43
src/foldingRangeProvider.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { View } from './views/abstract/view';
|
||||
import { getCurrentMagitRepo } from './utils/magitUtils';
|
||||
import { ChangeSectionView } from './views/changes/changesSectionView';
|
||||
import { ChangeView } from './views/changes/changeView';
|
||||
|
||||
export default class FoldingRangeProvider implements vscode.FoldingRangeProvider {
|
||||
|
||||
static scheme = { scheme: 'magit', language: 'magit-status' };
|
||||
|
||||
dispose() { }
|
||||
|
||||
provideFoldingRanges(document: vscode.TextDocument, context: vscode.FoldingContext, token: vscode.CancellationToken): vscode.ProviderResult<vscode.FoldingRange[]> {
|
||||
|
||||
let foldingRanges: vscode.FoldingRange[] = [];
|
||||
|
||||
let currentRepository = getCurrentMagitRepo();
|
||||
|
||||
if (currentRepository && currentRepository.views) {
|
||||
let currentView = currentRepository.views.get(document.uri.toString());
|
||||
if (currentView) {
|
||||
let views = this.flattenSubviews(currentView.subViews);
|
||||
|
||||
views.forEach( v => {
|
||||
if (v.isFoldable) {
|
||||
foldingRanges.push(new vscode.FoldingRange(v.range.start.line, v.range.end.line));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return foldingRanges;
|
||||
}
|
||||
|
||||
private flattenSubviews(subviews: View[]): View[] {
|
||||
|
||||
let flattened = [];
|
||||
subviews.forEach(sv => flattened.push(...this.flattenSubviews(sv.subViews)));
|
||||
|
||||
flattened.push(...subviews);
|
||||
|
||||
return flattened;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ export abstract class View {
|
||||
|
||||
subViews: View[] = [];
|
||||
range: Range = new Range(0, 0, 0, 0);
|
||||
isFoldable: boolean = false;
|
||||
abstract onClicked(): any;
|
||||
|
||||
render(startLineNumber: number): string[] {
|
||||
|
@ -6,6 +6,7 @@ import { Status } from "../../typings/git";
|
||||
import { ChangeHeaderView } from "./changeHeaderView";
|
||||
|
||||
export class ChangeView extends View {
|
||||
isFoldable = true;
|
||||
|
||||
constructor(private change: MagitChange) {
|
||||
super();
|
||||
|
@ -5,6 +5,7 @@ import { Section, SectionHeaderView } from "../sectionHeader";
|
||||
import { LineBreakView } from "../lineBreakView";
|
||||
|
||||
export class ChangeSectionView extends View {
|
||||
isFoldable = true;
|
||||
|
||||
constructor(section: Section, private changes: MagitChange[]) {
|
||||
super();
|
||||
|
@ -2,6 +2,7 @@ import { MagitChangeHunk } from "../../models/magitChangeHunk";
|
||||
import { TextView } from "../abstract/textView";
|
||||
|
||||
export class HunkView extends TextView {
|
||||
isFoldable = true;
|
||||
|
||||
constructor(private changeHunk: MagitChangeHunk) {
|
||||
super();
|
||||
|
Loading…
Reference in New Issue
Block a user