Skip to content

Commit 3a9e960

Browse files
committed
[json] improve folding stability with comments
1 parent eee1b9b commit 3a9e960

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

extensions/json/client/src/jsonMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function activate(context: ExtensionContext) {
7070
// The server is implemented in node
7171
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js'));
7272
// The debug options for the server
73-
let debugOptions = { execArgv: ['--nolazy', '--inspect=6046'] };
73+
let debugOptions = { execArgv: ['--nolazy', '--inspect=' + (9000 + Math.round(Math.random() * 10000))] };
7474

7575
// If the extension is launch in debug mode the debug server options are use
7676
// Otherwise the run options are used

extensions/json/language-configuration.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{ "open": "[", "close": "]", "notIn": ["string"] },
1313
{ "open": "(", "close": ")", "notIn": ["string"] },
1414
{ "open": "'", "close": "'", "notIn": ["string"] },
15+
{ "open": "/*", "close": "*/", "notIn": ["string"] },
1516
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
1617
{ "open": "`", "close": "`", "notIn": ["string", "comment"] }
1718
]

extensions/json/server/src/jsonServerMain.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import {
88
createConnection, IConnection,
99
TextDocuments, TextDocument, InitializeParams, InitializeResult, NotificationType, RequestType,
10-
DocumentRangeFormattingRequest, Disposable, ServerCapabilities, DocumentColorRequest, ColorPresentationRequest,
10+
DocumentRangeFormattingRequest, Disposable, ServerCapabilities, DocumentColorRequest, ColorPresentationRequest, Position,
1111
} from 'vscode-languageserver';
1212

1313
import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDescription } from 'request-light';
@@ -18,7 +18,7 @@ import Strings = require('./utils/strings');
1818
import { formatError, runSafe, runSafeAsync } from './utils/errors';
1919
import { JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration } from 'vscode-json-languageservice';
2020
import { getLanguageModelCache } from './languageModelCache';
21-
import { createScanner, SyntaxKind } from 'jsonc-parser';
21+
import { createScanner, SyntaxKind, ScanError } from 'jsonc-parser';
2222

2323
import { FoldingRangeType, FoldingRangesRequest, FoldingRange, FoldingRangeList, FoldingProviderServerCapabilities } from './protocol/foldingProvider.proposed';
2424

@@ -393,9 +393,13 @@ connection.onRequest(FoldingRangesRequest.type, params => {
393393
case SyntaxKind.BlockCommentTrivia: {
394394
let startLine = document.positionAt(scanner.getTokenOffset()).line;
395395
let endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line;
396-
if (startLine < endLine) {
397-
ranges.push({ startLine, endLine, type: FoldingRangeType.Comment });
398-
prevStart = startLine;
396+
if (scanner.getTokenError() === ScanError.UnexpectedEndOfComment && startLine + 1 < document.lineCount) {
397+
scanner.setPosition(document.offsetAt(Position.create(startLine + 1, 0)));
398+
} else {
399+
if (startLine < endLine) {
400+
ranges.push({ startLine, endLine, type: FoldingRangeType.Comment });
401+
prevStart = startLine;
402+
}
399403
}
400404
break;
401405
}

0 commit comments

Comments
 (0)