GithubHelp home page GithubHelp logo

Comments (5)

cyrusfirheir avatar cyrusfirheir commented on June 15, 2024 1
vscode.languages.registerFoldingRangeProvider({ pattern: "**/*.tw*" }, {
	provideFoldingRanges(document: vscode.TextDocument, context: vscode.FoldingContext) {
		const lines = document.getText().split(/\r?\n/);
		let r: vscode.FoldingRange[] = [];
		let open = 0;
		lines.forEach((el, i) => {
			const last = i === lines.length - 1;
			if (/^::.*/.test(el) || last) {
				if (open < i) r.push(new vscode.FoldingRange(open, i - (last ? 0 : 1), vscode.FoldingRangeKind.Region));
				open = i;
			}
		});
		return r;
	}
});

Providers for CompletionItem and FoldingRange (these I've tested, so far) overwrite normal plaintext behavior. There are issues open in the VSCode repo for this, but I doubt it's going to change anytime soon.

from twee3-language-tools.

cyrusfirheir avatar cyrusfirheir commented on June 15, 2024

I already had a Folding Range Provider set up, but then found out that custom providers kill indentation based folding.

A regex based folding in language configurations would be ideal, but as both the opening and closing tags are identical, and because it goes line by line, I haven't been able to settle on anything so far.

from twee3-language-tools.

MxAshUp avatar MxAshUp commented on June 15, 2024

Yeah I tried the regex-based config and ran into the same problem. I never considered this would have issues with indent-based folding. Do you still have the code for this?

from twee3-language-tools.

mielikki avatar mielikki commented on June 15, 2024

This doc https://code.visualstudio.com/docs/editor/codebasics#_folding seems to indicate that you can turn indentation folding back on (at least for some languages) if you don't want the syntax aware folding. Does that help? I'm fairly new to twee so I'm not sure when indentation folding would be useful in a twee file?

It would definitely be useful to collapse a file down to the passage titles to make it easy to re-order passages.

Since the 1.22 release, folding regions can also be computed based on syntax tokens of the editor's configured language.
The following languages already provide syntax aware folding: Markdown, HTML, CSS, LESS, SCSS, and JSON.

If you prefer to switch back to indentation-based folding for one (or all) of the languages above, use:

  "[html]": {
    "editor.foldingStrategy": "indentation"
  },

Regions can also be defined by markers defined by each language. The following languages currently have markers defined:

from twee3-language-tools.

cyrusfirheir avatar cyrusfirheir commented on June 15, 2024

@mielikki Unfortunately, no, that doesn't help. Turning it off doesn't help. Having it there allows for some sort of folding for those who do indent...

The problems with folding is described in the previous comments, and they're sadly still the same problems.

from twee3-language-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.