Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto indent support #13

Closed
jonom opened this issue Jan 9, 2019 · 15 comments
Closed

Auto indent support #13

jonom opened this issue Jan 9, 2019 · 15 comments

Comments

@jonom
Copy link
Contributor

jonom commented Jan 9, 2019

Thanks for this extension! It seems to work pretty well although I'm finding some of the things I can do with an html file don't work with a SS file. One example is auto indent... I like it when VSCode indents my lines automatically when I move them around. It seems a definition could be added to this extension to make that work, here is the info: https://code.visualstudio.com/updates/v1_14#_auto-indent-on-type-move-lines-and-paste

I'm not really following what is going on there but maybe it means something to you. I guess the indent rules could be copied from the html definition?

@jinjie
Copy link

jinjie commented Feb 13, 2020

Have you found a solution to this yet?

Installing this breaks many things that work with html syntax, including auto-indenting and emmet. I have to put these into my settings.json to have emmet working properly:

{
    "editor.tabCompletion": "on",
    "editor.snippetSuggestions": "top"
}

@jonom
Copy link
Contributor Author

jonom commented Feb 13, 2020

No but I've been playing around with an idea this morning. I'm thinking that .ss files are really just html files with a little bit of extra markup. Any extensions and functions that are available in vsCode for HTML you would want to be available for .ss files as well, but by treating .ss files as a separate language that doesn't happen (as far as I can see). So I think that rather than define a whole language for .ss files, it makes more sense to just use the base HTML language, but extend it a little bit.

I followed this guide on injecting grammars and was able to get some basic syntax highlighting happening with the following:

{
	"scopeName": "ss-template.injection",
	"injectionSelector": "L:text.html",
	"patterns": [
		{
			"include": "#ss-template-comment"
		},
		{
			"include": "#ss-template-tag"
		}
	],
	"repository": {
		"ss-template-comment": {
			"match": "<%--.*?--%>",
			"name": "comment.sscomment"
		},
		"ss-template-tag": {
			"match": "<%.*?%>",
			"name": "keyword.sstag"
		}
	}
}

Maybe exploring that approach, and associating .ss files with HTML language would be a good solution?

@gorriecoe
Copy link
Collaborator

@jonom Let me know if the latest update helps.

@jonom
Copy link
Contributor Author

jonom commented Jul 15, 2020

Thanks for all your work @gorriecoe! It looks like auto indenting works but gets confused by SS tags. Might be partially a stylistic thing.

indent

Also, not sure if it would be related but VSCode doesn't appear to know how to format .ss files

image

@gorriecoe
Copy link
Collaborator

gorriecoe commented Jul 15, 2020

Its probably my regex pattern. I have updated it to this:

<%\\s+(?:if|else|loop|with|control|cache|uncache)

I would like to simplify this to .* but found it would try and auto indent things like <% include %>.

As for the formatter, I'm not really sure. Could be your settings, as I changed the language name from uppercase to lowercase. However I kept uppercase as an alias. https://github.com/adrhumphreys/vscode-silverstripe/blob/master/package.json#L50-L54

@jonom
Copy link
Contributor Author

jonom commented Jul 15, 2020

So this feature works for you on .ss files?

I guess formatting might be too much to hope for since you can put SS tags anywhere... I can't imagine how you'd get perfect syntax highlighting or formatting when we can do things like this 😄

image

@gorriecoe
Copy link
Collaborator

gorriecoe commented Jul 15, 2020

No that feature doesn't work for me. =( Was it previously? I can investigate further.

For syntax highlighting its the same issue as #12 and is inherited from html. I can't figure out how to resolve this both via injection or include. Otherwise we would have to write an entire .ss syntax

@jonom
Copy link
Contributor Author

jonom commented Jul 16, 2020

@gorriecoe no it wasn't working before either so no problem there.

@gorriecoe
Copy link
Collaborator

@jonom The latest update should have resolved the indentation of cache and uncached

@jonom
Copy link
Contributor Author

jonom commented Jul 20, 2020

@gorriecoe seems to be working a lot better - thanks! I noticed that <h(x)> tags seem to cause things below them to be indented... in case you're a sucker for pain and want to look at that too 😆 Certainly no expectation. Huge thank you for your improvements so far.

indent2

@gorriecoe
Copy link
Collaborator

gorriecoe commented Jul 20, 2020

@jonom I would say its an issue with the closing tag being on the same line. The problem is a conflict of increase and decrease indention patterns. The increase of indent rule kicks in after the regex matches but the decrease before the regex match. If you try that with any html element this will occur. I have come across something similar and think I can fix this. Just a matter of checking and excluding any html closing tag that is on the same line from increasing its indentation. But yeah if you could confirm that is the issue that would be great.

@jonom
Copy link
Contributor Author

jonom commented Jul 20, 2020

@gorriecoe interesting - if I change the heading tag to a div (still all on one line) you're right, the same problem happens. Oddly though, if I put the heading opening and closing tags on their own lines, the issue still happens, even though it doesn't happen for the same structure with a div.

@gorriecoe
Copy link
Collaborator

@jonom 5a034ca. The latest update should resolve both the h1 and sameline issues. I'll get @adrhumphreys to publish it soon =)

@gorriecoe
Copy link
Collaborator

gorriecoe commented Jul 20, 2020

Published 1.0.4 should have this fixed =)

@jonom
Copy link
Contributor Author

jonom commented Jul 21, 2020

Legend! Thanks mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants