Skip to content

Commit

Permalink
LSP Backend (#1739)
Browse files Browse the repository at this point in the history
* Updated packages

* Use local packages, fix errors

* Adding LSP features

* New cache, more documentation, fixes, setup LSP service

* Add `LSPCompletionItemsUtil` Namespace

* Spruce up the lsp binary menu

* Propagate error, remove commented function

* Update CodeEditKit
---------

Co-authored-by: Khan Winter <[email protected]>
  • Loading branch information
FastestMolasses and thecoolwinter authored Jun 25, 2024
1 parent e8b1bf5 commit c78ef96
Show file tree
Hide file tree
Showing 40 changed files with 1,877 additions and 64 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type_name:
- ID

identifier_name:
allowed_symbols: ["$", "_"]
excluded:
- id
- vc
Expand Down
179 changes: 177 additions & 2 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"identity" : "codeeditkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditKit",
"location" : "https://github.com/CodeEditApp/CodeEditKit.git",
"state" : {
"revision" : "ad28213a968586abb0cb21a8a56a3587227895f1",
"version" : "0.1.2"
Expand All @@ -31,7 +31,7 @@
{
"identity" : "codeeditsourceeditor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditSourceEditor",
"location" : "https://github.com/CodeEditApp/CodeEditSourceEditor.git",
"state" : {
"revision" : "cf85789d527d569e94edfd674c5ac8071b244dd9",
"version" : "0.7.3"
Expand Down Expand Up @@ -73,6 +73,24 @@
"version" : "0.4.2"
}
},
{
"identity" : "fseventswrapper",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Frizlab/FSEventsWrapper",
"state" : {
"revision" : "70bbea4b108221fcabfce8dbced8502831c0ae04",
"version" : "2.1.0"
}
},
{
"identity" : "globpattern",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/GlobPattern",
"state" : {
"revision" : "4ebb9e89e07cc475efa74f87dc6d21f4a9e060f8",
"version" : "0.1.1"
}
},
{
"identity" : "grdb.swift",
"kind" : "remoteSourceControl",
Expand All @@ -82,6 +100,33 @@
"version" : "5.26.1"
}
},
{
"identity" : "jsonrpc",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/JSONRPC",
"state" : {
"revision" : "c6ec759d41a76ac88fe7327c41a77d9033943374",
"version" : "0.9.0"
}
},
{
"identity" : "languageclient",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/LanguageClient",
"state" : {
"revision" : "f8fdeaed850fbc3e542cd038e952758887f6be5d",
"version" : "0.8.0"
}
},
{
"identity" : "languageserverprotocol",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/LanguageServerProtocol",
"state" : {
"revision" : "ac76fccf0e981c8e30c5ee4de1b15adc1decd697",
"version" : "0.13.2"
}
},
{
"identity" : "logstream",
"kind" : "remoteSourceControl",
Expand All @@ -100,6 +145,24 @@
"version" : "0.2.1"
}
},
{
"identity" : "processenv",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/ProcessEnv",
"state" : {
"revision" : "83f1ebc9dd6fb1db0bd89a3fcae00488a0f3fdd9",
"version" : "1.0.0"
}
},
{
"identity" : "queue",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattmassicotte/Queue",
"state" : {
"revision" : "8d6f936097888f97011610ced40313655dc5948d",
"version" : "0.1.4"
}
},
{
"identity" : "rearrange",
"kind" : "remoteSourceControl",
Expand All @@ -109,6 +172,15 @@
"version" : "1.8.1"
}
},
{
"identity" : "semaphore",
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/Semaphore",
"state" : {
"revision" : "f1c4a0acabeb591068dea6cffdd39660b86dec28",
"version" : "0.0.8"
}
},
{
"identity" : "sparkle",
"kind" : "remoteSourceControl",
Expand Down
9 changes: 4 additions & 5 deletions CodeEdit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import SwiftUI
import CodeEditSourceEditor
import CodeEditSymbols
import CodeEditSourceEditor

final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
private let updater = SoftwareUpdater()
Expand Down Expand Up @@ -230,10 +230,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {

/// Setup all the services into a ServiceContainer for the application to use.
private func setupServiceContainer() {
// Example for how services will be instantiated
// ServiceContainer.register(
// PasteboardService()
// )
ServiceContainer.register(
LSPService()
)
}

extension AppDelegate {
Expand Down
3 changes: 1 addition & 2 deletions CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct AreaTabBar<Tab: AreaTab>: View {
case next
}

// swiftlint: disable function_parameter_count
// swiftlint:disable:next function_parameter_count
private func swapTab(
tab: Tab,
currentIndex: Int,
Expand Down Expand Up @@ -236,7 +236,6 @@ struct AreaTabBar<Tab: AreaTab>: View {
items.swapAt(currentIndex, swapIndex)
}
}
// swiftlint: enable function_parameter_count

private func isWithinPrevTopBounds(
_ curLocation: CGFloat, _ swapLocation: CGRect, _ swapWidth: CGFloat
Expand Down
97 changes: 56 additions & 41 deletions CodeEdit/Features/CodeEditUI/Views/KeyValueTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ private struct NewListTableItemView: View {
let keyColumnName: String
let valueColumnName: String
let newItemInstruction: String
let validKeys: [String]
let headerView: AnyView?
var completion: (String, String) -> Void

init(
_ keyColumnName: String,
_ valueColumnName: String,
_ newItemInstruction: String,
validKeys: [String],
headerView: AnyView? = nil,
completion: @escaping (String, String) -> Void
) {
self.keyColumnName = keyColumnName
self.valueColumnName = valueColumnName
self.newItemInstruction = newItemInstruction
self.validKeys = validKeys
self.headerView = headerView
self.completion = completion
}
Expand All @@ -44,8 +47,18 @@ private struct NewListTableItemView: View {
VStack(spacing: 0) {
Form {
Section {
TextField(keyColumnName, text: $key)
.textFieldStyle(.plain)
if validKeys.isEmpty {
TextField(keyColumnName, text: $key)
.textFieldStyle(.plain)
} else {
Picker(keyColumnName, selection: $key) {
ForEach(validKeys, id: \.self) { key in
Text(key).tag(key)
}
Divider()
Text("No Selection").tag("")
}
}
TextField(valueColumnName, text: $value)
.textFieldStyle(.plain)
} header: {
Expand Down Expand Up @@ -84,6 +97,7 @@ private struct NewListTableItemView: View {
struct KeyValueTable<Header: View>: View {
@Binding var items: [String: String]

let validKeys: [String]
let keyColumnName: String
let valueColumnName: String
let newItemInstruction: String
Expand All @@ -95,65 +109,66 @@ struct KeyValueTable<Header: View>: View {

init(
items: Binding<[String: String]>,
validKeys: [String] = [],
keyColumnName: String,
valueColumnName: String,
newItemInstruction: String,
@ViewBuilder header: @escaping () -> Header = { EmptyView() }
) {
self._items = items
self.validKeys = validKeys
self.keyColumnName = keyColumnName
self.valueColumnName = valueColumnName
self.newItemInstruction = newItemInstruction
self.header = header
}

var body: some View {
VStack {
Table(tableItems, selection: $selection) {
TableColumn(keyColumnName) { item in
Text(item.key)
}
TableColumn(valueColumnName) { item in
Text(item.value)
}
Table(tableItems, selection: $selection) {
TableColumn(keyColumnName) { item in
Text(item.key)
}
.frame(height: 200)
.actionBar {
HStack(spacing: 2) {
Button {
showingModal = true
} label: {
Image(systemName: "plus")
}
TableColumn(valueColumnName) { item in
Text(item.value)
}
}
.frame(height: 200)
.actionBar {
HStack(spacing: 2) {
Button {
showingModal = true
} label: {
Image(systemName: "plus")
}

Divider()
.frame(minHeight: 15)
Divider()
.frame(minHeight: 15)

Button {
removeItem()
} label: {
Image(systemName: "minus")
}
.disabled(selection == nil)
.opacity(selection == nil ? 0.5 : 1)
Button {
removeItem()
} label: {
Image(systemName: "minus")
}
Spacer()
.disabled(selection == nil)
.opacity(selection == nil ? 0.5 : 1)
}
.sheet(isPresented: $showingModal) {
NewListTableItemView(
keyColumnName,
valueColumnName,
newItemInstruction,
headerView: AnyView(header())
) { key, value in
items[key] = value
updateTableItems()
showingModal = false
}
Spacer()
}
.sheet(isPresented: $showingModal) {
NewListTableItemView(
keyColumnName,
valueColumnName,
newItemInstruction,
validKeys: validKeys,
headerView: AnyView(header())
) { key, value in
items[key] = value
updateTableItems()
showingModal = false
}
.clipShape(RoundedRectangle(cornerRadius: 6))
.onAppear(perform: updateTableItems)
}
.cornerRadius(6)
.onAppear(perform: updateTableItems)
}

private func updateTableItems() {
Expand Down
4 changes: 3 additions & 1 deletion CodeEdit/Features/Documents/WorkspaceDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
// Created by Pavel Kasila on 17.03.22.
//

import Foundation
import AppKit
import SwiftUI
import Combine
import Foundation
import LanguageServerProtocol

@objc(WorkspaceDocument)
final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
Expand Down Expand Up @@ -113,6 +114,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
workspaceURL: url,
editorManager: editorManager
)

self.workspaceFileManager = .init(
folderUrl: url,
ignoredFilesAndFolders: Set(ignoredFilesAndDirectory),
Expand Down
8 changes: 2 additions & 6 deletions CodeEdit/Features/Editor/Models/Editor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ final class Editor: ObservableObject, Identifiable {
default:
break
}

do {
try openFile(item: item)
} catch {
print(error)
}
}

/// Opens a tab in the editor.
Expand All @@ -201,6 +195,7 @@ final class Editor: ObservableObject, Identifiable {
tabs.append(item)
}
}

selectedTab = item
if !fromHistory {
history.removeFirst(historyOffset)
Expand All @@ -222,6 +217,7 @@ final class Editor: ObservableObject, Identifiable {
let contentType = try item.file.url.resourceValues(forKeys: [.contentTypeKey]).contentType
let codeFile = try CodeFileDocument(
for: item.file.url,
// TODO: FILE CONTENTS ARE READ MULTIPLE TIMES
withContentsOf: item.file.url,
ofType: contentType?.identifier ?? ""
)
Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Features/Editor/Models/EditorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class EditorManager: ObservableObject {
/// - editor: The editor to add the tab to. If nil, it is added to the active tab group.
func openTab(item: CEWorkspaceFile, in editor: Editor? = nil) {
let editor = editor ?? activeEditor
editor.openTab(file: item)
editor.openTab(file: item, asTemporary: false)
}

/// bind active tap group to listen to file selection changes.
Expand Down
Loading

0 comments on commit c78ef96

Please sign in to comment.