mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
Allow syntax tree to update when changing files
Previously when using the file based syntax tree, it would not update until a change had been made in the new file. Now we automatically update the syntax tree to match the current file.
This commit is contained in:
parent
1b4e0ec1c8
commit
0db95fc812
2 changed files with 26 additions and 17 deletions
|
@ -1,23 +1,32 @@
|
||||||
import { TextEditor } from 'vscode';
|
import { TextEditor } from 'vscode';
|
||||||
import { TextDocumentIdentifier } from 'vscode-languageclient';
|
import { TextDocumentIdentifier } from 'vscode-languageclient';
|
||||||
|
|
||||||
|
import {
|
||||||
|
SyntaxTreeContentProvider,
|
||||||
|
syntaxTreeUri
|
||||||
|
} from '../commands/syntaxTree';
|
||||||
import { Decoration } from '../highlighting';
|
import { Decoration } from '../highlighting';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
|
|
||||||
export async function handle(editor: TextEditor | undefined) {
|
export function makeHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
|
||||||
if (
|
return async function handle(editor: TextEditor | undefined) {
|
||||||
!Server.config.highlightingOn ||
|
if (!editor || editor.document.languageId !== 'rust') {
|
||||||
!editor ||
|
return;
|
||||||
editor.document.languageId !== 'rust'
|
}
|
||||||
) {
|
|
||||||
return;
|
syntaxTreeProvider.eventEmitter.fire(syntaxTreeUri);
|
||||||
}
|
|
||||||
const params: TextDocumentIdentifier = {
|
if (!Server.config.highlightingOn) {
|
||||||
uri: editor.document.uri.toString()
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const params: TextDocumentIdentifier = {
|
||||||
|
uri: editor.document.uri.toString()
|
||||||
|
};
|
||||||
|
const decorations = await Server.client.sendRequest<Decoration[]>(
|
||||||
|
'rust-analyzer/decorationsRequest',
|
||||||
|
params
|
||||||
|
);
|
||||||
|
Server.highlighter.setHighlights(editor, decorations);
|
||||||
};
|
};
|
||||||
const decorations = await Server.client.sendRequest<Decoration[]>(
|
|
||||||
'rust-analyzer/decorationsRequest',
|
|
||||||
params
|
|
||||||
);
|
|
||||||
Server.highlighter.setHighlights(editor, decorations);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,13 +94,13 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
notifications.publishDecorations.handle
|
notifications.publishDecorations.handle
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
|
||||||
|
|
||||||
// The events below are plain old javascript events, triggered and handled by vscode
|
// The events below are plain old javascript events, triggered and handled by vscode
|
||||||
vscode.window.onDidChangeActiveTextEditor(
|
vscode.window.onDidChangeActiveTextEditor(
|
||||||
events.changeActiveTextEditor.handle
|
events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider)
|
||||||
);
|
);
|
||||||
|
|
||||||
const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
|
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
'rust-analyzer',
|
'rust-analyzer',
|
||||||
|
|
Loading…
Reference in a new issue