Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

WIP: Merge both existing and rust-analyzer extension codebase #840

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Unreleased

* Update built-in Rust grammar

### 0.7.8 - 2020-05-13

* Rebrand extension as RLS-agnostic
Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@
".rs"
],
"configuration": "./language-configuration.json"
},
{
"id": "ra_syntax_tree",
"extensions": [
".rast"
]
}
],
"grammars": [
{
"language": "rust",
"scopeName": "source.rust",
"path": "rust.tmGrammar.json"
},
{
"language": "ra_syntax_tree",
"scopeName": "source.ra_syntax_tree",
"path": "ra_syntax_tree.tmGrammar.json"
}
],
"snippets": [
Expand Down
20 changes: 0 additions & 20 deletions rust-analyzer/editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,26 +632,6 @@
]
}
],
"languages": [
{
"id": "ra_syntax_tree",
"extensions": [
".rast"
]
}
],
"grammars": [
{
"language": "rust",
"scopeName": "source.rust",
"path": "rust.tmGrammar.json"
},
{
"language": "ra_syntax_tree",
"scopeName": "source.ra_syntax_tree",
"path": "ra_syntax_tree.tmGrammar.json"
}
],
"problemMatchers": [
{
"name": "rustc",
Expand Down
143 changes: 0 additions & 143 deletions rust-analyzer/editors/code/src/net.ts

This file was deleted.

51 changes: 33 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
workspace,
WorkspaceFolder,
WorkspaceFoldersChangeEvent,
Memento,
} from 'vscode';
import * as lc from 'vscode-languageclient';

import { RLSConfiguration } from './configuration';
import * as rls from './rls';
import * as rustAnalyzer from './rustAnalyzer';
import * as rustAnalyzer from './rust-analyzer';
import { rustupUpdate } from './rustup';
import { startSpinner, stopSpinner } from './spinner';
import { activateTaskProvider, Execution, runRlsCommand } from './tasks';
Expand All @@ -32,17 +33,21 @@ export interface Api {
}

export async function activate(context: ExtensionContext): Promise<Api> {
// Weave in global state when handling changed active text editor
const handleChangedActiveTextEd = (ed: TextEditor | undefined) =>
onDidChangeActiveTextEditor(ed, context.globalState);

context.subscriptions.push(
...[
configureLanguage(),
...registerCommands(),
workspace.onDidChangeWorkspaceFolders(whenChangingWorkspaceFolders),
window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor),
window.onDidChangeActiveTextEditor(handleChangedActiveTextEd),
],
);
// Manually trigger the first event to start up server instance if necessary,
// since VSCode doesn't do that on startup by itself.
onDidChangeActiveTextEditor(window.activeTextEditor);
handleChangedActiveTextEd(window.activeTextEditor);

// Migrate the users of multi-project setup for RLS to disable the setting
// entirely (it's always on now)
Expand Down Expand Up @@ -81,13 +86,16 @@ export async function deactivate() {
/** Tracks dynamically updated progress for the active client workspace for UI purposes. */
let progressObserver: Disposable | undefined;

function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
function onDidChangeActiveTextEditor(
editor: TextEditor | undefined,
globalState: Memento,
) {
if (!editor || !editor.document) {
return;
}
const { languageId, uri } = editor.document;

const workspace = clientWorkspaceForUri(uri, {
const workspace = clientWorkspaceForUri(uri, globalState, {
initializeIfMissing: languageId === 'rust' || languageId === 'toml',
});
if (!workspace) {
Expand Down Expand Up @@ -135,6 +143,7 @@ const workspaces: Map<string, ClientWorkspace> = new Map();
*/
function clientWorkspaceForUri(
uri: Uri,
globalState: Memento,
options?: { initializeIfMissing: boolean },
): ClientWorkspace | undefined {
const rootFolder = workspace.getWorkspaceFolder(uri);
Expand All @@ -149,7 +158,7 @@ function clientWorkspaceForUri(

const existing = workspaces.get(folder.uri.toString());
if (!existing && options && options.initializeIfMissing) {
const workspace = new ClientWorkspace(folder);
const workspace = new ClientWorkspace(folder, globalState);
workspaces.set(folder.uri.toString(), workspace);
workspace.autoStart();
}
Expand All @@ -173,15 +182,17 @@ export class ClientWorkspace {
private lc: lc.LanguageClient | null = null;
private disposables: Disposable[];
private _progress: Observable<WorkspaceProgress>;
private globalState: Memento;
get progress() {
return this._progress;
}

constructor(folder: WorkspaceFolder) {
constructor(folder: WorkspaceFolder, globalState: Memento) {
this.config = RLSConfiguration.loadFromWorkspace(folder.uri.fsPath);
this.folder = folder;
this.disposables = [];
this._progress = new Observable<WorkspaceProgress>({ state: 'standby' });
this.globalState = globalState;
}

/**
Expand All @@ -198,18 +209,22 @@ export class ClientWorkspace {
const { createLanguageClient, setupClient, setupProgress } =
this.config.engine === 'rls' ? rls : rustAnalyzer;

const client = await createLanguageClient(this.folder, {
updateOnStartup: this.config.updateOnStartup,
revealOutputChannelOn: this.config.revealOutputChannelOn,
logToFile: this.config.logToFile,
rustup: {
channel: this.config.channel,
path: this.config.rustupPath,
disabled: this.config.rustupDisabled,
const client = await createLanguageClient(
this.folder,
{
updateOnStartup: this.config.updateOnStartup,
revealOutputChannelOn: this.config.revealOutputChannelOn,
logToFile: this.config.logToFile,
rustup: {
channel: this.config.channel,
path: this.config.rustupPath,
disabled: this.config.rustupDisabled,
},
rls: { path: this.config.rlsPath },
rustAnalyzer: this.config.rustAnalyzer,
},
rls: { path: this.config.rlsPath },
rustAnalyzer: this.config.rustAnalyzer,
});
this.globalState,
);

client.onDidChangeState(({ newState }) => {
if (newState === lc.State.Starting) {
Expand Down
Loading