Skip to content

Commit

Permalink
feat: implement intentions based rename
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Apr 12, 2021
1 parent 0516e36 commit 35f957e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/auto-languageclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,46 @@ export default class AutoLanguageClient {
}))
}

public provideIntentions() {
return {
grammarScopes: this.getGrammarScopes(), // [*] would also work
getIntentions: async ({ textEditor, bufferPosition }: { textEditor: TextEditor; bufferPosition: Point }) => {
const intentions: { title: string, selected: () => void }[] = []
const server = await this._serverManager.getServer(textEditor)

if (server == null) {
return intentions
}

if (RenameAdapter.canAdapt(server.capabilities)) {
const outcome = { possible: true, label: 'Rename' }
if (RenameAdapter.canPrepare(server.capabilities)) {
const { possible } = await RenameAdapter.prepareRename(server.connection, textEditor, bufferPosition)
outcome.possible = possible
}

if (outcome.possible) {
intentions.push({
title: outcome.label,
selected: async () => {
const newName = await Dialog.prompt('Enter new name')
return RenameAdapter.rename(server.connection, textEditor, bufferPosition, newName)
}
})
}
}

intentions.push({
title: 'Some dummy intention',
selected: async () => {
console.log('selected')
}
})

return intentions
}
}
}

protected async getRename(
editor: TextEditor,
Expand Down

0 comments on commit 35f957e

Please sign in to comment.