Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

SVG Code Hints (#10084) #10294

Merged
merged 1 commit into from
Jan 14, 2015
Merged

SVG Code Hints (#10084) #10294

merged 1 commit into from
Jan 14, 2015

Conversation

sprintr
Copy link
Contributor

@sprintr sprintr commented Jan 1, 2015

This is a follow up of #10084, adds Code Hints for SVG.

CC: @redmunds

"clip-rule": {
"attribOptions": ["evenodd", "inherit", "nonzero"]
},
"color": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to align this with ColorUtils.js.
Unfortunately, we only have a comprehensive regexp right now, including rgb, hex, ...

You should at least include rebeccapurple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebeccapurple was not available in SVG 1.1 spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently do not provide the list of defined colors for CSS Code Hints. For the sake of consistency, seems like we should provide them in both places or neither. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though rebeccapurple is not in the spec, I just tested using it in Chrome (in a SVG, of course) and it worked. I guess some will use it, and it won't hurt if we have it in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelgerber I have removed all color properties for now to be consistent with CSS hinting. Will add it later including rebeccapurple once we get them in CSS too.

@redmunds redmunds self-assigned this Jan 1, 2015
@@ -0,0 +1,242 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the spec, attributes are organized into groups such as "conditional processing attributes", "core attributes", "graphical event attributes", "presentation attributes", "xlink attributes", etc.

I think it would reduce a lot of redunancy which would make future maintenance easier if this organization could be captured in the json data. For example, define each of the "attribute groups" as a list of attributes, and then any tag that uses a particular attribute group could simply specify a flag (e.g. "coreAttrs": true).

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll get that organized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format looks great!

Since this data has both tags and attributes, I think the term "groups" is a little vague. What about using "attributeGroups" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like attributeGroups.

@redmunds
Copy link
Contributor

redmunds commented Jan 1, 2015

@sprintr This is an awesome contribution! Thanks for all of the unit tests.

I made a first pass through the extension. Things generally look and work good. I'll need to make a more detailed pass through the code, but I wanted to give my initial feedback.

function _getTagAttributes(editor, constPos) {
var pos, ctx, ctxPrev, ctxNext, ctxTemp, tagName, exclusionList = [], shouldReplace;

pos = $.extend({}, constPos);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use _.clone(constPos) here. It's more obvious (but you'll need to getModule thirdparty/lodash)

(same below)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$.extend({}, constPos) is OK here. It's used in many places in the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that since constPos is multiple levels deep, I think you need to do a deep copy:

        pos = $.extend(true, {}, constPos);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, constPos is not multiple levels deep, but ctx (a few lines below) is, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I thought it was a range.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, pos works both ways.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it works both ways, but only use deep copying if needed.

@sprintr
Copy link
Contributor Author

sprintr commented Jan 2, 2015

Alright, will make the proposed changes today. I don't know about copyright of it.

@sprintr
Copy link
Contributor Author

sprintr commented Jan 3, 2015

@redmunds @marcelgerber I have made the changes, Do I have to write unit tests for SVGUtils too after I rename it to XMLUtils and keep it in languages directory?

@sprintr
Copy link
Contributor Author

sprintr commented Jan 3, 2015

@redmunds @marcelgerber The new format of SVGTags.json

@sprintr
Copy link
Contributor Author

sprintr commented Jan 3, 2015

@redmunds I will work on caching attributes tomorrow.

TokenValue = 3;

// Regex to find whether or not an attribute value is quoted in single or double quotation marks.
var regexQuotedValue = /^['"][\W\w]*?['"]?$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[\W\w] is everything (like .), right?
In that case, you should rather use .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that done because JSLint complained about using .*?? If so, you can add the regexp: true jslint var.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was the reason.

@redmunds
Copy link
Contributor

redmunds commented Jan 3, 2015

@sprintr

The new format of SVGTags.json

Very nice! So much easier to read and update.

@redmunds
Copy link
Contributor

redmunds commented Jan 3, 2015

@sprintr

Do I have to write unit tests for SVGUtils too after I rename it to XMLUtils and keep it in languages directory?

That would be great! The token values set in CodeMirror have changed in the past and broken things, so this will make it easier to detect and fix any cases in the future.

There are really only 2 API calls that you're providing (the others are static values), so it only needs to be a few tests that the API call returns expected values.

* Return the tagName and a list of attributes used by the tag.
*
* @param {Editor} editor An instance of active editor
* @param {line: int, ch: int} constPos The position of cursor in the active editor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be something like {!{line: number, ch: number}}

@sprintr
Copy link
Contributor Author

sprintr commented Jan 7, 2015

I am facing a problem with brackets.getModule, after transferring XMLUtils.js to language/, I am not able to require it via brackets.getModule.

When I use brackets.getModule("language/XMLUtils"), I face the following error.

[Extension] failed to load G:/brackets/brackets-svg/src/extensions/default/SVGCodeHints - Error: Module name "language/XMLUtils" has not been loaded yet for context: _

and using require("language/XMLUtils"), the result is.

GET file:///G:/brackets/brackets-svg/src/extensions/default/SVGCodeHints/language/XMLUtils.js net::ERR_FILE_NOT_FOUND
[Extension] failed to load G:/brackets/brackets-svg/src/extensions/default/SVGCodeHints - Module does not exist: file:///G:/brackets/brackets-svg/src/extensions/default/SVGCodeHints/language/XMLUtils.js

Working with XMLUtils = require("../../../language/XMLUtils"), works just fine. any suggestion?

CC: @redmunds @marcelgerber

@marcelgerber
Copy link
Contributor

Yeah, you have to require it in brackets.js. Also make sure to include it in brackets.test.

@redmunds redmunds changed the title [REVIEW ONLY] SVG Code Hints [REVIEW ONLY] SVG Code Hints (#10084) Jan 7, 2015
@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2015

Note that SVG code hints do not work in <svg> tags embedded in HTML docs. We'll need to submit a change to the CodeMIrror htmlmixed mode to fix this, so it's not required for this pull request.

});

it("should exclude hints if they are already been used.", function () {
// In first <rect, after <rect+space
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: should be "should exclude hints if they have already been used."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, How did I miss that, will get it fixed tomorrow.

@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2015

Done with code review.

@sprintr
Copy link
Contributor Author

sprintr commented Jan 8, 2015

@redmunds I will work on caching and those grammatical mistakes today. I think caching also needs a review.

@sprintr
Copy link
Contributor Author

sprintr commented Jan 9, 2015

@redmunds caching has been implemented in getTagAttributes(), you may wanna have a look at it.

cachedAttributes[tagName] = cachedAttributes[tagName].concat(tagData.attributeGroups[group]);
}
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caching looks good. The only change I would make would be to sort the list here so it doesn't have to be sorted every time the cached list is used. It's ok if getHints() calls sort() on list every time since it is fast if list is already sorted.

@redmunds
Copy link
Contributor

redmunds commented Jan 9, 2015

@sprintr Just one a couple more comments about the code.

Note that after that's fixed the commits will need to be squashed into a single commit to keep the code base cleaner.

@sprintr
Copy link
Contributor Author

sprintr commented Jan 9, 2015

@redmunds For HTML, brackets is not using fuzzy matching. That's what I kept in mind.

@redmunds
Copy link
Contributor

redmunds commented Jan 9, 2015

@sprintr

For HTML, brackets is not using fuzzy matching.

OK. Implement it if you want, but it's ok if not.

@sprintr
Copy link
Contributor Author

sprintr commented Jan 13, 2015

@redmunds Fuzzy hinting has been implemented, you can try it. If you think it is OK, then I can squash commits.

@redmunds
Copy link
Contributor

@sprintr Looks good. Squash away!

@sprintr
Copy link
Contributor Author

sprintr commented Jan 14, 2015

@redmunds squashed!

Update copyright notice.

Change SVGTags.json to newer format.

Adjust to the new format.

Remove color from hints

Add new line to unittests.js

Format

Simplify attribute options exclusion list

More simplification to SVGUtils.js

Updated comment

Updated unittests.js for the changes.

Improved format of SVGTags.json

Refactoring

Removed an error

Remove alias properties to increase simplicity

Add missing SVG attributes

Cleanup

Some more refactoring

Updated unit tests

Moved XMLUtils to core

Added XMLUtils to brackets.js

Added tests for XMLUtils-test.js

Require XMLUtils

Removed tabs

Removed some more tabs.

New line at the end.

Removed tab.

Removed unused variables.

Remove XMLUtils from integration testing modules.

Correct whitespace regex.

Made proposed changes.

Removed unused variables.

Use a better name for attribute groups.

Removed mistakes in unit tests

Implement caching of attributes

More optimization

Refactor XMLUtils

Sort cached attributes.

Move preferences up

Some more restrictions in XMLUtils

Add fuzzy hinting

Format

Fix a bug with hinting

Merge SVG code hints
@sprintr sprintr changed the title [REVIEW ONLY] SVG Code Hints (#10084) SVG Code Hints (#10084) Jan 14, 2015
@redmunds
Copy link
Contributor

Thanks for this awesome contribution! Merging.

redmunds added a commit that referenced this pull request Jan 14, 2015
@redmunds redmunds merged commit ba96598 into adobe:master Jan 14, 2015
@sprintr
Copy link
Contributor Author

sprintr commented Jan 14, 2015

Cool! It has been a privilege to work on Brackets.

@rawat11
Copy link

rawat11 commented Feb 2, 2015

@sprintr I tried embedding svg code directly in the html file since brackets supports HTML5, and was able to view it in the browser but Live Preview doesn't work in this case ??? I have to explicitly refresh the page ??
Have we implemented this ?

@sprintr
Copy link
Contributor Author

sprintr commented Feb 2, 2015

htmlmixed mode (of CodeMirror) doesn't support SVG, so we don't have code hints inside HTML files. Live preview for SVG has not been implemented.

@rawat11
Copy link

rawat11 commented Feb 3, 2015

@sprintr okkay.
So for brackets we have htmlmixed mode. But code hints work in it.

@sprintr
Copy link
Contributor Author

sprintr commented Feb 3, 2015

Brackets uses htmlmixed mode for HTML documents, and it doesn't support SVG right now. SVG code hints for now only work in SVG documents.

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

Successfully merging this pull request may close these issues.

5 participants