Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve some special cases for selection ranges #939

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix some typings
  • Loading branch information
Legend-Master committed Nov 27, 2023
commit 803d5c521f6820a3d890cfd4dcf285d533e16a7b
5 changes: 1 addition & 4 deletions src/languageservice/services/yamlSelectionRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { yamlDocumentsCache } from '../parser/yaml-documents';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { ASTNode } from 'vscode-json-languageservice';

export function getSelectionRanges(document: TextDocument, positions: Position[]): SelectionRange[] | undefined {
if (!document) {
return;
}
export function getSelectionRanges(document: TextDocument, positions: Position[]): SelectionRange[] {
const doc = yamlDocumentsCache.getYamlDocument(document);
return positions.map((position) => {
const ranges = getRanges(position);
Expand Down
2 changes: 1 addition & 1 deletion src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface LanguageService {
deleteSchemaContent: (schemaDeletions: SchemaDeletions) => void;
deleteSchemasWhole: (schemaDeletions: SchemaDeletionsAll) => void;
getFoldingRanges: (document: TextDocument, context: FoldingRangesContext) => FoldingRange[] | null;
getSelectionRanges: (document: TextDocument, positions: Position[]) => SelectionRange[] | undefined;
getSelectionRanges: (document: TextDocument, positions: Position[]) => SelectionRange[];
getCodeAction: (document: TextDocument, params: CodeActionParams) => CodeAction[] | undefined;
getCodeLens: (document: TextDocument) => PromiseLike<CodeLens[] | undefined> | CodeLens[] | undefined;
resolveCodeLens: (param: CodeLens) => PromiseLike<CodeLens> | CodeLens;
Expand Down
10 changes: 6 additions & 4 deletions test/yamlSelectionRanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ function isRangesEqual(range1: Range, range2: Range): boolean {
);
}

function expectSelections(selectionRange: SelectionRange, ranges: Range[]): void {
function expectSelections(selectionRange: SelectionRange | undefined, ranges: Range[]): void {
for (const range of ranges) {
expect(selectionRange.range).eql(range);
expect(selectionRange?.range).eql(range);

// Deduplicate ranges
while (selectionRange.parent && isRangesEqual(selectionRange.range, selectionRange.parent.range)) {
while (selectionRange?.parent && isRangesEqual(selectionRange.range, selectionRange.parent.range)) {
selectionRange = selectionRange.parent;
}
selectionRange = selectionRange.parent;

selectionRange = selectionRange?.parent;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"outDir": "./out/server",
"sourceMap": true,
"target": "es2020",
"allowSyntheticDefaultImports": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"include": [ "src", "test" ],
Expand Down