{"action":"created","issue":{"url":"https://api.github.com/repos/atom/atom/issues/16087","repository_url":"https://api.github.com/repos/atom/atom","labels_url":"https://api.github.com/repos/atom/atom/issues/16087/labels{/name}","comments_url":"https://api.github.com/repos/atom/atom/issues/16087/comments","events_url":"https://api.github.com/repos/atom/atom/issues/16087/events","html_url":"https://github.com/atom/atom/pull/16087","id":270848328,"number":16087,"title":"Use new TextBuffer LanguageMode API","user":{"login":"maxbrunsfeld","id":326587,"avatar_url":"https://avatars3.githubusercontent.com/u/326587?v=4","gravatar_id":"","url":"https://api.github.com/users/maxbrunsfeld","html_url":"https://github.com/maxbrunsfeld","followers_url":"https://api.github.com/users/maxbrunsfeld/followers","following_url":"https://api.github.com/users/maxbrunsfeld/following{/other_user}","gists_url":"https://api.github.com/users/maxbrunsfeld/gists{/gist_id}","starred_url":"https://api.github.com/users/maxbrunsfeld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxbrunsfeld/subscriptions","organizations_url":"https://api.github.com/users/maxbrunsfeld/orgs","repos_url":"https://api.github.com/users/maxbrunsfeld/repos","events_url":"https://api.github.com/users/maxbrunsfeld/events{/privacy}","received_events_url":"https://api.github.com/users/maxbrunsfeld/received_events","type":"User","site_admin":true},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2017-11-03T00:20:40Z","updated_at":"2017-11-28T19:21:03Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/atom/atom/pulls/16087","html_url":"https://github.com/atom/atom/pull/16087","diff_url":"https://github.com/atom/atom/pull/16087.diff","patch_url":"https://github.com/atom/atom/pull/16087.patch"},"body":"Depends on https://github.com/atom/text-buffer/pull/260\r\n\r\nThis is a continuation of work started in https://github.com/atom/atom/pull/15713, with the overall goal of allowing Atom to use parsing systems other than TextMate grammars.\r\n\r\n### One Language Per Buffer\r\n\r\nThe main user-facing change introduced in this PR is that language modes (previously called `TokenizedBuffers`) now belong to a `TextBuffer`, not an individual `TextEditor`. This means that if have you have a file open in 3 different tabs, the file will only be parsed once instead of 3 times for the purpose of syntax highlighting. It also means that when you select a language for the file using the [grammar selector](https://github.com/atom/grammar-selector), your choice will apply in *all* 3 places.\r\n\r\n### TextEditor API Changes\r\n\r\nPreviously, the way to configure an editor's language was to assign to the editor a TextMate `Grammar`, and the editor would internally construct a `TokenizedBuffer` which would use the `first-mate` APIs to parse the buffer.\r\n\r\nNow, the `TextEditor` class is no longer responsible for constructing its parser directly; it relies on the buffer having a *language mode* which provides information about syntax highlighting, folding, commenting, and suggested indentation.\r\n\r\nThis means that the `.getGrammar` and `.setGrammar` methods don't really make sense any more, and neither does the `grammar` parameter to the `TextEditor` constructor. These APIs will continue to work for backwards-compatibility, but will be deprecated at some point.\r\n\r\n### Other API Changes\r\n\r\nOther language-related APIs like `TextEditorRegistry.setGrammarOverride` were designed around the TextMate concept of *scope names* - strings like `source.js` that are intended to fit into TextMate's scope selector system. Though scope selectors will continue to be a concept in Atom, we will no longer assume that these selectors use the TextMate-style naming conventions. Where possible, we will identify languages by their common name, instead of assuming that they have a special *scope* name that is different from their regular name.\r\n\r\nSince TextEditors no longer construct their own language modes, I've moved this functionality into the existing `GrammarRegistry` object exposed as `atom.grammars`. It is implemented in the following methods:\r\n\r\n* `atom.grammars.assignLanguageMode(buffer, languageId)` - Assign the buffer a language mode that uses the language with the given id. For textmate grammars, we use the `scopeName` (e.g. `source.js`) as an ID. Tree-sitter grammars will have different looking ids (probably just `javascript`, `go`, etc).\r\n\r\n* `atom.grammars.autoAssignLanguageMode(buffer)` - Assign the buffer a language mode that uses the most appropriate language, based on the buffer's file extension and content.\r\n\r\n* `atom.grammars.maintainLanguageMode(buffer)` - Assign the buffer a language mode and continue to *update* the language mode as additional language packages are loaded, or the buffer's file path changes.\r\n\r\nThe `TextEditorRegistry` is no longer responsible for anything to do with grammars. The grammar-related methods will continue to work but they will be deprecated sometime soon.\r\n\r\n### Remaining Tasks\r\n\r\n* [ ] Rename `TokenizedBuffer` to `TextMateLanguageMode`\r\n* [ ] Track visibility correctly when a language mode is used by multiple editors\r\n\r\n### Next Steps\r\n\r\nIt should now be possible to integrate [Tree-sitter](https://github.com/tree-sitter/tree-sitter) parsers into Atom just by changing the `GrammarRegistry` and the `PackageManager`. The core editor no longer assumes anything about how its parser works. Once this is merged, I will begin doing this."},"comment":{"url":"https://api.github.com/repos/atom/atom/issues/comments/347634271","html_url":"https://github.com/atom/atom/pull/16087#issuecomment-347634271","issue_url":"https://api.github.com/repos/atom/atom/issues/16087","id":347634271,"user":{"login":"maxbrunsfeld","id":326587,"avatar_url":"https://avatars3.githubusercontent.com/u/326587?v=4","gravatar_id":"","url":"https://api.github.com/users/maxbrunsfeld","html_url":"https://github.com/maxbrunsfeld","followers_url":"https://api.github.com/users/maxbrunsfeld/followers","following_url":"https://api.github.com/users/maxbrunsfeld/following{/other_user}","gists_url":"https://api.github.com/users/maxbrunsfeld/gists{/gist_id}","starred_url":"https://api.github.com/users/maxbrunsfeld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxbrunsfeld/subscriptions","organizations_url":"https://api.github.com/users/maxbrunsfeld/orgs","repos_url":"https://api.github.com/users/maxbrunsfeld/repos","events_url":"https://api.github.com/users/maxbrunsfeld/events{/privacy}","received_events_url":"https://api.github.com/users/maxbrunsfeld/received_events","type":"User","site_admin":true},"created_at":"2017-11-28T19:21:03Z","updated_at":"2017-11-28T19:21:03Z","author_association":"CONTRIBUTOR","body":"@Alhadis @damieng @50Wliu I've updated the PR to remove the use of language *names* in `assignLanguageMode`. The method now takes a parameter called `languageId`. For TextMate grammars, this will just be the `scopeName`, so that grammars will continue to be identified primarily by their `scopeName` as before.\r\n\r\nTree-sitter grammars will have their *ids* that will look a bit different: `javascript`, `ruby`, `c++`."}}
{"actor":{"display_login":"maxbrunsfeld"}}