Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import type {
CompletionList,
CancellationToken,
DidChangeConfigurationParams,
DidChangeConfigurationRegistrationOptions
DidChangeConfigurationRegistrationOptions,
SelectionRangeParams
} from 'vscode-languageserver/node';
import {
SemanticTokensRequest,
Expand Down Expand Up @@ -221,6 +222,7 @@ export class LanguageServer {
},
definitionProvider: true,
hoverProvider: true,
selectionRangeProvider: true,
executeCommandProvider: {
commands: [
CustomCommands.TranspileFile
Expand Down Expand Up @@ -563,6 +565,14 @@ export class LanguageServer {
return result;
}

@AddStackToErrorMessage
public async onSelectionRanges(params: SelectionRangeParams) {
this.logger.debug('onSelectionRanges', params);

const srcPath = util.uriToPath(params.textDocument.uri);
return this.projectManager.getSelectionRanges({ srcPath: srcPath, positions: params.positions });
}

@AddStackToErrorMessage
public async onDocumentSymbol(params: DocumentSymbolParams) {
this.logger.debug('onDocumentSymbol', params);
Expand Down
26 changes: 24 additions & 2 deletions src/Program.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as assert from 'assert';
import * as fsExtra from 'fs-extra';
import * as path from 'path';
import type { CodeAction, CompletionItem, Position, Range, SignatureInformation, Location, DocumentSymbol, CancellationToken } from 'vscode-languageserver';
import type { CodeAction, CompletionItem, Position, Range, SignatureInformation, Location, DocumentSymbol, CancellationToken, SelectionRange } from 'vscode-languageserver';
import { CancellationTokenSource, CompletionItemKind } from 'vscode-languageserver';
import type { BsConfig, FinalizedBsConfig } from './BsConfig';
import { Scope } from './Scope';
import { DiagnosticMessages } from './DiagnosticMessages';
import { BrsFile } from './files/BrsFile';
import { XmlFile } from './files/XmlFile';
import type { BsDiagnostic, File, FileReference, FileObj, BscFile, SemanticToken, AfterFileTranspileEvent, FileLink, ProvideHoverEvent, ProvideCompletionsEvent, Hover, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent } from './interfaces';
import type { BsDiagnostic, File, FileReference, FileObj, BscFile, SemanticToken, AfterFileTranspileEvent, FileLink, ProvideHoverEvent, ProvideCompletionsEvent, Hover, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent, ProvideSelectionRangesEvent } from './interfaces';
import { standardizePath as s, util } from './util';
import { XmlScope } from './XmlScope';
import { DiagnosticFilterer } from './DiagnosticFilterer';
Expand Down Expand Up @@ -1064,6 +1064,28 @@ export class Program {
}
}

/**
* Get the selection ranges for the given positions in a file. Used for expand/shrink selection.
* @param srcPath path to the file
* @param positions the positions to get selection ranges for
*/
public getSelectionRanges(srcPath: string, positions: Position[]): SelectionRange[] {
const file = this.getFile(srcPath);
if (file) {
const event: ProvideSelectionRangesEvent = {
program: this,
file: file,
positions: positions,
selectionRanges: []
};
this.plugins.emit('beforeProvideSelectionRanges', event);
this.plugins.emit('provideSelectionRanges', event);
this.plugins.emit('afterProvideSelectionRanges', event);
return event.selectionRanges;
}
return [];
}

/**
* Compute code actions for the given file and range
*/
Expand Down
7 changes: 6 additions & 1 deletion src/bscPlugin/BscPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isBrsFile, isXmlFile } from '../astUtils/reflection';
import type { BeforeFileTranspileEvent, Plugin, OnFileValidateEvent, OnGetCodeActionsEvent, ProvideHoverEvent, OnGetSemanticTokensEvent, OnScopeValidateEvent, ProvideCompletionsEvent, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent } from '../interfaces';
import type { BeforeFileTranspileEvent, Plugin, OnFileValidateEvent, OnGetCodeActionsEvent, ProvideHoverEvent, OnGetSemanticTokensEvent, OnScopeValidateEvent, ProvideCompletionsEvent, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent, ProvideSelectionRangesEvent } from '../interfaces';
import type { Program } from '../Program';
import { CodeActionsProcessor } from './codeActions/CodeActionsProcessor';
import { CompletionsProcessor } from './completions/CompletionsProcessor';
Expand All @@ -14,6 +14,7 @@ import { ProgramValidator } from './validation/ProgramValidator';
import { ScopeValidator } from './validation/ScopeValidator';
import { XmlFileValidator } from './validation/XmlFileValidator';
import { WorkspaceSymbolProcessor } from './symbols/WorkspaceSymbolProcessor';
import { SelectionRangesProcessor } from './selectionRanges/SelectionRangesProcessor';

export class BscPlugin implements Plugin {
public name = 'BscPlugin';
Expand Down Expand Up @@ -46,6 +47,10 @@ export class BscPlugin implements Plugin {
new ReferencesProvider(event).process();
}

public provideSelectionRanges(event: ProvideSelectionRangesEvent) {
new SelectionRangesProcessor(event).process();
}

public onGetSemanticTokens(event: OnGetSemanticTokensEvent) {
if (isBrsFile(event.file)) {
return new BrsFileSemanticTokensProcessor(event as any).process();
Expand Down
Loading