Skip to content

Commit

Permalink
feat: Support LSP actions across workspace folders
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Jun 17, 2024
1 parent 69fdeb5 commit 385b6b8
Show file tree
Hide file tree
Showing 37 changed files with 1,373 additions and 1,472 deletions.
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Added
- Validate even-odd register requirements of machine instructions
- Support configuration in user or workspace settings
- Support LSP actions across workspace folders

#### Fixed
- Accept additional URI schemes based on currently opened workspaces
Expand Down
15 changes: 3 additions & 12 deletions clients/vscode-hlasmplugin/src/hlasmExternalFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import * as vscode from 'vscode';
import * as vscodelc from 'vscode-languageclient';
import { asError, isCancellationError } from "./helpers";
import { uriFriendlyBase16Encode } from "./conversions";
import { deflate, inflate, sha256 } from './tools';
import { textDecode } from './tools.common';

Expand Down Expand Up @@ -153,8 +152,6 @@ interface ClientInstance<ConnectArgs, ReadArgs extends ClientUriDetails, ListArg
dispose: () => void,
};

function asFragment(s: string) { return s ? '#' + s : ''; }

type ChannelType = {
onNotification(method: string, handler: vscodelc.GenericNotificationHandler): vscode.Disposable;
sendNotification<P>(type: vscodelc.NotificationType<P>, params?: P): Promise<void>;
Expand Down Expand Up @@ -236,7 +233,6 @@ export class HLASMExternalFiles {
instance: null,
details: null,
server: null,
associatedWorkspaceFragment: null,
});

private async extractUriDetails<ConnectArgs, ReadArgs extends ClientUriDetails, ListArgs extends ClientUriDetails>(uri: vscode.Uri, rawUri: string, purpose: ExternalRequestType): Promise<{
Expand All @@ -245,21 +241,18 @@ export class HLASMExternalFiles {
instance: null;
details: null;
server: null;
associatedWorkspaceFragment: null;
} | {
cacheKey: string;
service: string;
instance: ClientInstance<ConnectArgs, ReadArgs, ListArgs>;
details: ExternalRequestDetails<ReadArgs, ListArgs>[typeof purpose],
server: ConnectArgs;
associatedWorkspaceFragment: string;
} | {
cacheKey: string;
service: string;
instance: null;
details: null;
server: null;
associatedWorkspaceFragment: string;
}> {
// skip schema, skip :, skip optional //server, extract service, extract path, end on query or fragment
const rawPathParser = /^[^:/?#]+:(?:\/\/[^/?#]*)?\/([A-Z]+)(\/[^#?]*)?(?:[?#]|$)/;
Expand All @@ -283,7 +276,6 @@ export class HLASMExternalFiles {
instance: instance,
details: details,
server: server,
associatedWorkspaceFragment: uri.fragment
};
}
else
Expand All @@ -293,7 +285,6 @@ export class HLASMExternalFiles {
instance: null,
details: null,
server: null,
associatedWorkspaceFragment: uri.fragment
};
}

Expand All @@ -319,7 +310,7 @@ export class HLASMExternalFiles {
this.channel?.sendNotification(vscodelc.DidChangeWatchedFilesNotification.type, {
changes: (vscode.workspace.workspaceFolders || []).map(w => {
return {
uri: `${this.magicScheme}:/${service}${asFragment(uriFriendlyBase16Encode(w.uri.toString()))}`,
uri: `${this.magicScheme}:/${service}`,
type: vscodelc.FileChangeType.Changed
};
})
Expand Down Expand Up @@ -528,7 +519,7 @@ export class HLASMExternalFiles {
responseTransform: (result: T, pathTransform: (p: string) => string) => (T extends string[] ? ExternalListDirectoryResponse : ExternalReadFileResponse)['data']):
Promise<(T extends string[] ? ExternalListDirectoryResponse : ExternalReadFileResponse) | ExternalErrorResponse | null> {
if (msg.op !== ExternalRequestType.read_file && msg.op !== ExternalRequestType.list_directory) throw Error("");
const { cacheKey, service, instance, details, server, associatedWorkspaceFragment } = await this.extractUriDetails<ConnectArgs, ReadArgs, ListArgs>(uri, msg.url, msg.op);
const { cacheKey, service, instance, details, server } = await this.extractUriDetails<ConnectArgs, ReadArgs, ListArgs>(uri, msg.url, msg.op);
if (!cacheKey || instance && !details)
return this.generateError(msg.id, -5, 'Invalid request');

Expand All @@ -548,7 +539,7 @@ export class HLASMExternalFiles {
}
content.references.add(msg.url);

const { response, cache } = await this.transformResult(msg.id, content, x => responseTransform(x, x => `${this.magicScheme}:/${service}${x}${asFragment(associatedWorkspaceFragment)}`));
const { response, cache } = await this.transformResult(msg.id, content, x => responseTransform(x, x => `${this.magicScheme}:/${service}${x}`));

if (cache && instance && !content.cached)
content.cached = await this.storeCachedResult(await serverId(details, instance), service, details.normalizedPath(), content.result);
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/debugging/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class debugger::impl final : public processing::statement_analyzer, output_handl
}
resp.provide(true);
debug_lib_provider debug_provider(std::move(dc.libraries), *dc.fm);
workspaces::file_manager_vfm vfm(*dc.fm, std::move(dc.workspace_uri));
workspaces::file_manager_vfm vfm(*dc.fm);

if (auto prefetch = debug_provider.prefetch_libraries(); prefetch.valid())
co_await std::move(prefetch);
Expand Down
1 change: 0 additions & 1 deletion parser_library/src/debugging/debugger_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ struct debugger_configuration
{
workspaces::file_manager* fm = nullptr;
std::vector<std::shared_ptr<workspaces::library>> libraries;
utils::resource::resource_location workspace_uri = utils::resource::resource_location();
asm_option opts;
std::vector<preprocessor_options> pp_opts;
};
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/tagged_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace hlasm_plugin::parser_library {

template<typename Tag, /* std::integral */ typename T = std::size_t>
template<typename Tag, std::integral T = std::size_t>
class index_t
{
static constexpr T invalid_index = (T)-1;
Expand Down
Loading

0 comments on commit 385b6b8

Please sign in to comment.