{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/language-server-protocol/issues/543","repository_url":"https://api.github.com/repos/Microsoft/language-server-protocol","labels_url":"https://api.github.com/repos/Microsoft/language-server-protocol/issues/543/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/language-server-protocol/issues/543/comments","events_url":"https://api.github.com/repos/Microsoft/language-server-protocol/issues/543/events","html_url":"https://github.com/Microsoft/language-server-protocol/issues/543","id":349103270,"node_id":"MDU6SXNzdWUzNDkxMDMyNzA=","number":543,"title":"Order of application for additionalTextEdits and textEdit on CompletionRequest","user":{"login":"kadircet","id":897555,"node_id":"MDQ6VXNlcjg5NzU1NQ==","avatar_url":"https://avatars1.githubusercontent.com/u/897555?v=4","gravatar_id":"","url":"https://api.github.com/users/kadircet","html_url":"https://github.com/kadircet","followers_url":"https://api.github.com/users/kadircet/followers","following_url":"https://api.github.com/users/kadircet/following{/other_user}","gists_url":"https://api.github.com/users/kadircet/gists{/gist_id}","starred_url":"https://api.github.com/users/kadircet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kadircet/subscriptions","organizations_url":"https://api.github.com/users/kadircet/orgs","repos_url":"https://api.github.com/users/kadircet/repos","events_url":"https://api.github.com/users/kadircet/events{/privacy}","received_events_url":"https://api.github.com/users/kadircet/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-08-09T12:19:30Z","updated_at":"2018-12-19T22:01:51Z","closed_at":"2018-12-19T11:39:03Z","author_association":"NONE","body":"Hello everyone,\r\n\r\nI believe there is a big ambiguity about in which order TextEdits should be applied on completion requests. Also there is no clarification about what would happen if one of the text edits changes the document in a way that ranges in the remaining text edits are not valid.\r\n\r\nLet me clarify with an example, let's say we have a reply of the following sort:\r\n```\r\n{\r\n   \"id\":4,\r\n   \"jsonrpc\":\"2.0\",\r\n   \"result\":{\r\n      \"isIncomplete\":false,\r\n      \"items\":[\r\n         {\r\n            \"additionalTextEdits\":[\r\n               {\r\n                  \"newText\":\"->\",\r\n                  \"range\":{\r\n                     \"end\":{\r\n                        \"character\":7,\r\n                        \"line\":85\r\n                     },\r\n                     \"start\":{\r\n                        \"character\":6,\r\n                        \"line\":85\r\n                     }\r\n                  }\r\n               }\r\n            ],\r\n            \"detail\":\"void\",\r\n            \"filterText\":\"pop_back\",\r\n            \"insertText\":\"pop_back()\",\r\n            \"insertTextFormat\":2,\r\n            \"kind\":2,\r\n            \"label\":\" pop_back()\",\r\n            \"sortText\":\"3fe51eb8pop_back\",\r\n            \"textEdit\":{\r\n               \"newText\":\"pop_back()\",\r\n               \"range\":{\r\n                  \"end\":{\r\n                     \"character\":7,\r\n                     \"line\":85\r\n                  },\r\n                  \"start\":{\r\n                     \"character\":7,\r\n                     \"line\":85\r\n                  }\r\n               }\r\n            }\r\n         }\r\n      ]\r\n   }\r\n}\r\n```\r\n\r\nAnd on the code side let's say we have this:\r\n```\r\nstd::shared_ptr<std::vector<int>> asdf;\r\nasdf.^\r\n```\r\nWhere \"^\" indicates current cursor position when requesting textedit(Let's assume cursor is on line 85 column 7). When this completion is applied one would expect to see:\r\n\"asdf->pop_back()\" but unfortunately that's not the case, at least on VSCode. Instead it results in:\r\n\"asdf-pop_back()\". I don't know the exact cause but my initial thoughts are on order of application, like it first applies additionaltextedit which converts the line from \"asdf.\" into \"asdf->\". Afterwards when it tries to apply main textEdit it doesn't update the location and instead writes over \">\" sign and results in asdf-pop_back.\r\n\r\n\r\nI think additionalTextEdit's requires some more clarification especially when the edits are on the same line. Otherwise there are some undefined behaviors like the one I mentioned above. I suggest it can be clarified by saying that:\r\n```\r\nFirst textEdit or insertText is applied and afterwards additionalTextEdits are applied in the order they are given. \r\n```\r\n\r\nAnd in addition to clarification on ordering, there might be some more words on ranges as well, for example:\r\n```\r\nRanges on these edit's are assumed to be on original document.\r\n```\r\nor maybe,\r\n```\r\nSince the edits on same line might change effect of other textEdits, LSP server should put the elements on the same line in back to front order. So that no change would effect another.\r\n```\r\n\r\nHave a nice day!"},"comment":{"url":"https://api.github.com/repos/Microsoft/language-server-protocol/issues/comments/448759498","html_url":"https://github.com/Microsoft/language-server-protocol/issues/543#issuecomment-448759498","issue_url":"https://api.github.com/repos/Microsoft/language-server-protocol/issues/543","id":448759498,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODc1OTQ5OA==","user":{"login":"dbaeumer","id":1931590,"node_id":"MDQ6VXNlcjE5MzE1OTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1931590?v=4","gravatar_id":"","url":"https://api.github.com/users/dbaeumer","html_url":"https://github.com/dbaeumer","followers_url":"https://api.github.com/users/dbaeumer/followers","following_url":"https://api.github.com/users/dbaeumer/following{/other_user}","gists_url":"https://api.github.com/users/dbaeumer/gists{/gist_id}","starred_url":"https://api.github.com/users/dbaeumer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbaeumer/subscriptions","organizations_url":"https://api.github.com/users/dbaeumer/orgs","repos_url":"https://api.github.com/users/dbaeumer/repos","events_url":"https://api.github.com/users/dbaeumer/events{/privacy}","received_events_url":"https://api.github.com/users/dbaeumer/received_events","type":"User","site_admin":false},"created_at":"2018-12-19T22:01:51Z","updated_at":"2018-12-19T22:01:51Z","author_association":"MEMBER","body":"That would be breaking :-).\r\n\r\nOut of curiosity: why is one edit not enough ?"}}
{"actor":{"display_login":"dbaeumer"}}