Get mispellings


#1

I am trying to build a package that interacts with misspelling markers created by spell-check. So far, I have found no way to get the markers generated by the spell-check package, neither through direct access to the array of markers in the spell-check code nor through somehow accessing the decorations in the current text editor buffer.

How can I get the locations in the buffer of all misspellings marked by spell-check?


#2

This is how the spell-check package does it:


#3

Sorry, I have the source in front of me. I’m asking how I can reference that from outside the spell-check package. How do i access spell-check's @viewsByEditor? The closest I’ve gotten is atom.packages.getActivePackage('spell-check'), but that returns metadata about the package. I don’t see any hooks into the actual variables inside the package.

I’ve also explored editor.getMarkerLayer(), editor.getMarkers(), and editor.getDefaultMarkerLayer(). The first option requires an ID, which I do not know. The second returns an empty array (in a text document with several decorated misspellings). The third returns a MarkerLayer with an ID of 0, but this seems to contain no markers.


#4

You don’t need to access the spell-check package for that. You just need to figure out if the spell-check package uses the default MarkerLayer or a named one. I would assume a named one. Then yes, you can use TextEditor.getMarkerLayer to retrieve the marker layer and get the markers.


#5

Sorry, added an edit above about Marker Layers. I didn’t realize MarkerLayers had names! I’ll look into that!


#6

Yeah, actually I’m not sure where I got the names idea from :frowning: I think I was remembering an earlier discussion as they were being implemented. It seems they’re only using IDs now which are opaque as to who created them. I think your use case is important though, so if you wouldn’t mind opening an Issue on https://github.com/atom/atom to expose marker layer IDs somehow where they’re used? I’ll point the devs at it and see if we can come up with a more elegant solution.


#7

Thanks. You just saved me from a major wild goose chase, as the documentation has nothing on names :stuck_out_tongue:

https://github.com/atom/atom/issues/11175


#8

You could write a provider/consumer service for spell-check that exposes those values also. I was thinking about doing that for my linter/status/quickfix-menu ideas once I get the current PR done. Not sure if that would be a good approach, but it would expose the API in a safe-ish manner.


#9

I was thinking more of just having an Atom API like TextEditor.registerMarkerLayer("name", id) that keeps a map of them. Then you could read from it with TextEditor.getMarkerLayer() and pass it the name or the ID and it would figure it out.


#10

There is an item to consider use linter for showing errors, which would get rid of the spelling marker layer entirely and move it over to that plugin for rendering. That might be a conflict with what @redbassett intends to use it for or make it moot entirely.

I was thinking the linter approach would be a good one since it already has a count of errors and a list of errors and warnings (which is nice since it is hard to see all the typos in the document). And it consolidates errors if you have a grammar plugin already using it (which is what I’m hoping for).

The registerMarkerLayer would have other uses.


#11

A spell check package that uses linter would be useless to me because I don’t use linter :grinning:


#12

Ideally, spell-check having an API would be great, however I initially started this project with the intention of building on top of the current package as-is. It does turn out I need a feature request to complete this however I feel like having the ability to retrieve a MarkerLayer is useful beyond the scope of extending the features of spell-check.


#13

Bah, that takes all the fun out of it. :stuck_out_tongue:

I think it would think using linter would avoid duplication of effort highlighting sections of text, reporting errors, etc. But, there are cases where you might not want to use it. Would it make sense to teach spell-check how to either have multiple outputs based on what is available or tell it how to provide an error list via a service and then use a separate package for the actual rendering/handling of the errors? That way, you could have a default display which works like today (and could be shipped as the default one) or a linter-based on for those who want it integrated with that system?


#14

I think a linter-based spell-check package would be awesome, don’t get me wrong. It just wouldn’t work for me … but that’s ok because Atom is about customizability :smile: I think a couple of the best linter plugins available are linter-write-good and linter-just-say-no. So having a linter-spell-check makes total sense.